Is it possible to have a Recoil-esque state management solution in Svelte?
I have an app where there is a "canvas" (just a div) that renders multiple elements. These elements (svgs or divs) are moveable/draggable/rotatable etc.
If I used a single svelte store for this, then the whole store would need to be updated every time any element is updated.
In React, the Recoil library solves this problem very elegantly. I'm wondering if it's possible to do something similar in Svelte.
Here is a basic attempt that seems to work. Please advise if I could improve in any way or if there are downsides to doing this.
import { writable, get } from "svelte/store";
let id = 0;
export const stateStore = writable({});
export const elementListStore = writable([]);
export function createElementStore(element) {
stateStore.update(store => {
store[++id] = writable(element);
return store;
})
return id;
}
export function getElementState(id) {
const store = get(stateStore);
console.log('store: ', store)
return store[id];
}