Reputation: 1
Is it possible to get the last state of a store that is derived from a custom store in svelte?
export const derivedState(customStore, (derived) => {
// what i would like to do here is something like
if (derived.status === 'OK'){
// do something and with derived and return
} else {
// return whatever the last value of derivedState was
}
}
Upvotes: 0
Views: 751
Reputation: 5426
Store the last state outside and update when appropriate
let lastState;
export const derivedState(customStore, (derived) => {
if (derived.status === 'OK'){
lastState = computeNewStateSomehow(derived);
}
return lastState;
}
Upvotes: 1