Comment by yokljo

Comment by yokljo 2 days ago

1 reply

I strongly suspect I know what that does because I worked with Svelte 4 for years (you no longer have to do this in Svelte 5. I can recommend Svelte 5, it's nice).

Basically, assigning a state to itself tells it to signal that that state has changed and update anything that is listening to it. The `state` object is actually a JS Proxy returned by createState [0], which allows intercepting the assignment to the `windows` property and emit signals. Usually you dont have to do that, but in this case, the proxy doesn't notice that `state.windows.push(X)` is a mutation. Only assignments directly to the state object count as mutations.

TLDR, `state.windows = state.windows` tells the framework that `windows` changed.

[0]: https://github.com/MercuryWorkshop/dreamlandjs/blob/1e7a34a1...

foxmoss 2 days ago

I was drafting a reply when you sent this, this is the correct interpretation and why I did it.