Is it possible to subscribe to particular properties in a object wrapped by a store?

I have a usecase in which I have an object with say 100+ properties. I have some function which I would like to execute only when property 52 changes. Is it possible to do something like this?
const someFunction = () => {
if (props.data["property52"]) {
// do something...
} else {
// do nothing
}
}
const someFunction = () => {
if (props.data["property52"]) {
// do something...
} else {
// do nothing
}
}
Will this function only trigger whenever the value of property52 updates? Or when any value of the data object changes?
6 Replies
apollo79
apollo7916mo ago
If you have the data object as a store, it will only update when property52 updates, if it is a plain object, it will update if you replace the complete data object Here you will only see two logs of "rerunning": https://playground.solidjs.com/anonymous/d232c219-e131-4917-9bb0-c44e3c934b68
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
TicTacMan
TicTacManOP16mo ago
Hi, thanks for the explanation! Do you know if there is a way to access the old value of store?
apollo79
apollo7916mo ago
Where do you want to access it?
TicTacMan
TicTacManOP16mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
TicTacMan
TicTacManOP16mo ago
Just a short description of what im trying to do: The third input field is a calculated field whose dependencies are supplied via an array called dependencies. Now I want to trigger an API call whenever any of the dependencies of the third field change In this case, input field 3 depends on data properties 50-55. Input field 1 changes property value 51 (so a change in field 1 should trigger an API call) and input field 2 changes property value 66 (a change in field 2 should not trigger an API call) The issue with my current example is that I need to maintain a separate array called "changedFields". Because on initial render, I would like field 3 to be empty since none of its dependencies have changed. the If I had access to the old value of the store, I would not need changedFields
apollo79
apollo7916mo ago
Okay... So what you could do would be just adding a isFirstRun variable or storing the current contents of the store after every rerun of getCalculatedValue, which would be much heavier I think. From what I can see, probably the isFirstRun is the cheaper version here. But the example is maybe a bit oversimplified, because I don't really know why you have that many fields, so there might be a better solution, but I can't see it from the context atm
Want results from more Discord servers?
Add your server