S
SolidJS14mo ago
Driver

Controls

Hi all, I'm trying to use createStore from the API. I want to subscribe to change the store object itself, not its fields. But its behavior is different from the example https://www.solidjs.com/tutorial/stores_mutation?solved If I change the array to the object in the example, its new values are output to the console. But if I open the same page playground in incognito or copy the code into a new project, it stops working. https://stackblitz.com/edit/solidjs-templates-l4mwrx?file=src%2FApp.tsx https://playground.solidjs.com/anonymous/6477c80b-93ee-4345-a33c-4b875c9b26ea This problem is driving me crazy, because I'm trying to write a store with history and undo/redo functionality for the second day and it keeps failing.
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
No description
No description
9 Replies
andi
andi14mo ago
any reason for using effect and not createEffect? replacing it should fix things, not even sure what effect does
thetarnav
thetarnav14mo ago
effect is createRenderEffect afaik
Driver
DriverOP14mo ago
Habits from Angular But still, I changed the effect to createEffect and the inconsistent behavior persists. What the hell?
No description
thetarnav
thetarnav14mo ago
same for me it's weird that incognito changes anything but also it shouldn't be reactive at all like if you tried that outside of a playground, the effect wouldn't rerun becasue this is not accessing any property of a store
console.log(`todos`, todos)
console.log(`todos`, todos)
it only works in the playground because the devtools console is not the actual chrome console, it patches console.log or something
Driver
DriverOP14mo ago
Weird, that's for sure. But I expected this behavior based on the tutorial, how do I subscribe to the changes in the whole store then?
thetarnav
thetarnav14mo ago
store.property to listen to a single property { ...store } to listen to a single object trackStore(store) from solid-primitives to listen to any nested change but generally you track what you use, you shouldn't really need to "track the whole thing" that often
Driver
DriverOP14mo ago
Yeah, but I'm trying to write a store with history and undo/redo functionality, so I need to make a shallow copy of the store on every change. May be there is already something like that in solid-primitives?
thetarnav
thetarnav14mo ago
you can copy the whole store or copy only the obj that changed by using captureStoreUpdates Also you can look at https://primitives.solidjs.community/package/history#observing-stores
Want results from more Discord servers?
Add your server