Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deep objects in effect state #101

Open
ratacat opened this issue Aug 28, 2019 · 2 comments
Open

deep objects in effect state #101

ratacat opened this issue Aug 28, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@ratacat
Copy link
Contributor

ratacat commented Aug 28, 2019

It seems like some unexpected behaviors can happen when using deep objects in an effect state. I have an array of nested objects in an effect definition. Once the effect is activated, it starts editing / rearranging though nested objects.

If multiple copies of the effect are created later, the state of the deep objects that are edited is copied over to the new effects. So it seems to me that the weird part is actually that the definition of the effect is being rewritten.

I ended up working around it for the moment by creating a deep copy of the original nested objected before working on them within the effect.

this.state.messageList = JSON.parse(JSON.stringify(this.state.messageListOriginal));

But thought I'd post about it to hear any thoughts from everyone.

@shawncplus
Copy link
Member

Yeah the workaround for this is to put that exact line of code into the effect's effectAdded listener. A possible core fix for this would be to add this.state = JSON.parse(JSON.stringify(this.state)); to EffectList#add so that as soon as an effect is added to an entity it gets its own copy of state

@shawncplus shawncplus added the bug Something isn't working label Aug 28, 2019
azigler added a commit to azigler/core that referenced this issue Jun 7, 2020
@azigler
Copy link

azigler commented Jun 7, 2020

I addressed this in #121.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants