superframe icon indicating copy to clipboard operation
superframe copied to clipboard

[state] state managed objects do not get updated correctly

Open mattrei opened this issue 6 years ago • 6 comments

When I bind a state object to a component the A-Frame core function updateProperties (src/core/components.js) is called. In this function there is the following code: skipTypeChecking = attrValue !== null && typeof this.previousAttrValue === 'object' && attrValue === this.previousAttrValue;

However when changing the properties via this state component, the this.previousAttrValue reference does not change although the contents may have changed and therefore the skipTypeChecking value is wrong and the component does not get updated correctly...

I think the state components clearObject function should instantiate a new reference and not reuse the old one. function clearObject (obj) { var key; for (key in obj) { delete obj[key]; } }

Then the this.previousAttrValue === attrValue is not the same anymore.

Hope you get my description. Thx for all your efforts!

mattrei avatar Oct 28 '17 11:10 mattrei

Oops, GitHub didn't notify me of these issues. I'll check on them, thanks!

ngokevin avatar Nov 04 '17 09:11 ngokevin

Can you provide an example component and input? Yeah, that core logic can be confusing with object references kept and such. But hasn't been a problem for multi-property components yet.

ngokevin avatar Nov 04 '17 09:11 ngokevin

see here this example: https://glitch.com/edit/#!/state-selector-problem

the this.data.entity is a string however it should be a selected DOM node.

See above where the problem (imo) is hiding.

mattrei avatar Nov 04 '17 16:11 mattrei

A workaround would be to use a string type rather the selector and run/store the selector yourself. This might be a bigger problem with A-Frame when using selector property type with skipTypeChecking.

ngokevin avatar Nov 07 '17 18:11 ngokevin

Thx for looking into it. Yes I am using this workaround however its a bit clumsy in the end ;). But this component is so wonderful, so I will totally stick to that.

Don't you think the problem lies within the clearObject function, that it we could solve the problem by getting a new reference eacht time or would this stress the garbage collector too much (without the need to patch A-Frame).

mattrei avatar Nov 08 '17 19:11 mattrei

Not using clearObject would just be a workaround that would add more work to the garbage collector, yeah. Related, I should change it to not delete the key but set to undefined instead though.

ngokevin avatar Nov 08 '17 23:11 ngokevin