diff --git a/packages/inula-next/src/CompNode.js b/packages/inula-next/src/CompNode.js index 23eb1d74135f12449257a0a44de8b6965d40e24c..5368589e3ee5d91c8ca57cda387d2b488252c31e 100644 --- a/packages/inula-next/src/CompNode.js +++ b/packages/inula-next/src/CompNode.js @@ -161,11 +161,18 @@ export class CompNode extends DLNode { /** * @brief Set a prop directly, if this is a forwarded prop, go and init forwarded props * @param key - * @param value + * @param valueFunc * @param deps */ _$setProp(key, valueFunc, deps) { if (this._$cache(key, deps)) return; + if (key === '*spread*') { + const spread = valueFunc(); + Object.keys(spread).forEach(key => { + this.updateProp(key, this[key]); + }); + return; + } this[key] = valueFunc(); this.updateProp(key, this[key]); } diff --git a/packages/inula-next/src/index.js b/packages/inula-next/src/index.js index d7f55295f19d6b8382dbe08188de0320e12ed897..6f77ecc6f1be4bf873e0dcaa30b5109b066bf02c 100644 --- a/packages/inula-next/src/index.js +++ b/packages/inula-next/src/index.js @@ -70,6 +70,9 @@ export function inMount() { * @property {(newValue: any, bit: number) => {} updateDerived */ export function Comp(compFn, props = {}) { + if (props['*spread*']) { + props = { ...props, ...props['*spread*'] }; + } return mountNode(() => new CompNode(), compFn, props); } diff --git a/packages/inula-next/test/props.test.tsx b/packages/inula-next/test/props.test.tsx index a04a0cbc6643aa532e02e31eb86ce2db6f8db6ca..c5c7c33ee6a5e15b7664f6e3680e65a755e44212 100644 --- a/packages/inula-next/test/props.test.tsx +++ b/packages/inula-next/test/props.test.tsx @@ -278,11 +278,13 @@ describe('extended prop tests', () => { `); }); - it.fails('should correctly spread props', ({ container }) => { + it('should correctly spread props', ({ container }) => { function Child(props) { return (
- {props.a} {props.b} {props.c} + {props.a} + {props.b} + {props.c}
); } @@ -296,7 +298,9 @@ describe('extended prop tests', () => { expect(container).toMatchInlineSnapshot(`
- Hello World ! + Hello + World + !
`); @@ -321,9 +325,9 @@ describe('extended prop tests', () => { `); }); - it.fails('should handle props without values', ({ container }) => { + it('should handle props without values', ({ container }) => { function Child({ isDisabled }) { - return ; + return ; } function App() { @@ -332,12 +336,15 @@ describe('extended prop tests', () => { render(App, container); expect(container).toMatchInlineSnapshot(` -
- -
- `); +
+ +
+ `); }); it('should handle props with expressions', ({ container }) => {