Fix a core system issue blocking preset-plugin wrapComponents
cc: 3968
This commit is contained in:
@@ -336,18 +336,23 @@ function systemExtend(dest={}, src={}) {
|
||||
// Parses existing components in the system, and prepares them for wrapping via getComponents
|
||||
if(src.wrapComponents) {
|
||||
objMap(src.wrapComponents, (wrapperFn, key) => {
|
||||
const ori = dest.components[key]
|
||||
const ori = dest.components && dest.components[key]
|
||||
if(ori && Array.isArray(ori)) {
|
||||
dest.components[key] = ori.concat([wrapperFn])
|
||||
delete src.wrapComponents[key]
|
||||
} else if(ori) {
|
||||
dest.components[key] = [ori, wrapperFn]
|
||||
} else {
|
||||
dest.components[key] = null
|
||||
delete src.wrapComponents[key]
|
||||
}
|
||||
})
|
||||
|
||||
if(!Object.keys(src.wrapComponents).length) {
|
||||
// only delete wrapComponents if we've matched all of our wrappers to components
|
||||
// this handles cases where the component to wrap may be out of our scope,
|
||||
// but a higher recursive `combinePlugins` call will be able to handle it.
|
||||
delete src.wrapComponents
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Account for wrapActions, make it an array and append to it
|
||||
|
||||
@@ -136,4 +136,58 @@ describe("wrapComponents", () => {
|
||||
expect(children.eq(0).text()).toEqual("Original component")
|
||||
expect(children.eq(1).text()).toEqual("WOW much data")
|
||||
})
|
||||
|
||||
it("should wrap correctly when registering more plugins", function(){
|
||||
|
||||
// Given
|
||||
|
||||
const mySystem = new System({
|
||||
plugins: [
|
||||
() => {
|
||||
return {
|
||||
statePlugins: {
|
||||
doge: {
|
||||
selectors: {
|
||||
wow: () => () => {
|
||||
return "WOW much data"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
wow: () => <div>Original component</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
mySystem.register([
|
||||
function() {
|
||||
return {
|
||||
// Wrap the component and use the system
|
||||
wrapComponents: {
|
||||
wow: (OriginalComponent, system) => (props) => {
|
||||
return <container>
|
||||
<OriginalComponent {...props}></OriginalComponent>
|
||||
<div>{system.dogeSelectors.wow()}</div>
|
||||
</container>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
// Then
|
||||
var Component = mySystem.getSystem().getComponents("wow")
|
||||
const wrapper = render(<Component name="Normal" />)
|
||||
|
||||
const container = wrapper.children().first()
|
||||
expect(container[0].name).toEqual("container")
|
||||
|
||||
const children = container.children()
|
||||
expect(children.length).toEqual(2)
|
||||
expect(children.eq(0).text()).toEqual("Original component")
|
||||
expect(children.eq(1).text()).toEqual("WOW much data")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user