superframe
superframe copied to clipboard
[state] state managed objects do not get updated correctly
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!
Oops, GitHub didn't notify me of these issues. I'll check on them, thanks!
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.
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.
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
.
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).
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.