Extended getComponent: system availability
This commit is contained in:
@@ -227,8 +227,17 @@ export default class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getComponents(component) {
|
getComponents(component) {
|
||||||
if(typeof component !== "undefined")
|
const res = this.system.components[component]
|
||||||
|
|
||||||
|
if(Array.isArray(res)) {
|
||||||
|
return res.reduce((ori, wrapper) => {
|
||||||
|
return wrapper(ori, this.getSystem())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if(typeof component !== "undefined") {
|
||||||
return this.system.components[component]
|
return this.system.components[component]
|
||||||
|
}
|
||||||
|
|
||||||
return this.system.components
|
return this.system.components
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,17 +331,16 @@ function systemExtend(dest={}, src={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wrap components
|
// Wrap components
|
||||||
// Parses existing components in the system, injects new wrappers into the dest,
|
// Parses existing components in the system, and prepares them for wrapping via getComponents
|
||||||
// and removes wrapComponents from the src so it doesn't make it into the final system
|
|
||||||
if(src.wrapComponents) {
|
if(src.wrapComponents) {
|
||||||
objMap(src.wrapComponents, (wrapper, key) => {
|
objMap(src.wrapComponents, (wrapperFn, key) => {
|
||||||
if(src.components && src.components[key]) {
|
const ori = dest.components[key]
|
||||||
// eslint-disable-next-line no-console
|
if(ori && Array.isArray(ori)) {
|
||||||
console.warn("Warning: providing and wrapping the same component simultaneously is not supported.")
|
dest.components[key] = ori.concat([wrapperFn])
|
||||||
}
|
} else if(ori) {
|
||||||
|
dest.components[key] = [ori, wrapperFn]
|
||||||
if(dest.components[key]) {
|
} else {
|
||||||
dest.components[key] = wrapper(dest.components[key])
|
dest.components[key] = null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ describe("wrapComponents", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it.skip("should provide a reference to the system to the wrapper", function(done){
|
it("should provide a reference to the system to the wrapper", function(){
|
||||||
|
|
||||||
// Given
|
// Given
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ describe("wrapComponents", () => {
|
|||||||
wow: (OriginalComponent, system) => (props) => {
|
wow: (OriginalComponent, system) => (props) => {
|
||||||
return <container>
|
return <container>
|
||||||
<OriginalComponent {...props}></OriginalComponent>
|
<OriginalComponent {...props}></OriginalComponent>
|
||||||
<OriginalComponent name="Wrapped"></OriginalComponent>
|
<div>{system.dogeSelectors.wow()}</div>
|
||||||
</container>
|
</container>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ describe("wrapComponents", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
var Component = system.getSystem().getComponents("wow")
|
var Component = mySystem.getSystem().getComponents("wow")
|
||||||
const wrapper = render(<Component name="Normal" />)
|
const wrapper = render(<Component name="Normal" />)
|
||||||
|
|
||||||
const container = wrapper.children().first()
|
const container = wrapper.children().first()
|
||||||
@@ -134,6 +134,6 @@ describe("wrapComponents", () => {
|
|||||||
const children = container.children()
|
const children = container.children()
|
||||||
expect(children.length).toEqual(2)
|
expect(children.length).toEqual(2)
|
||||||
expect(children.eq(0).text()).toEqual("Original component")
|
expect(children.eq(0).text()).toEqual("Original component")
|
||||||
expect(children.eq(1).text()).toEqual("Wrapped component")
|
expect(children.eq(1).text()).toEqual("WOW much data")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user