From 9a6503b0e84b701f0c0b06daa9d86ee71e877a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=B8=80=E5=86=B0?= <14512567+sunyibing@user.noreply.gitee.com> Date: Sat, 14 Sep 2024 10:53:17 +0800 Subject: [PATCH] fix: fix props bugs --- packages/inula-next/src/CompNode.js | 9 +++++++- packages/inula-next/src/index.js | 3 +++ packages/inula-next/test/props.test.tsx | 29 +++++++++++++++---------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/packages/inula-next/src/CompNode.js b/packages/inula-next/src/CompNode.js index 23eb1d74..5368589e 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 d7f55295..6f77ecc6 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 a04a0cbc..c5c7c33e 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 (