-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Description
const o = vanX.reactive({});
van.derive(() => console.log(o.p)); // only undefined
o.p = "new";It will cause unexpected issues with components with optional props:
const defineComponent = (setup, defaultProps) => {
const props = vanX.reactive(defaultProps);
const dom = setup(props);
return {
dom,
update: (patchProps) => Object.assign(props, defaultProps, patchProps),
};
};
const Comp = defineComponent(
(props) => van.tags.p({ textContent: () => props.text }),
{},
);
van.add(document.body, Comp.dom);
Comp.update({ text: 'new' }); // won't updateSo I have to use a Proxy to decorate the reactive object:
new Proxy(vanX.reactive({}), {
get(target, prop, receiver) {
Object.prototype.hasOwnProperty.call(target, prop) || (target[prop] = void 0); // add property
return Reflect.get(target, prop, receiver); // track deps
},
});Metadata
Metadata
Assignees
Labels
No labels