This is a great small library I just found, good work : ) There's a minor issue with TypeScript that would be great if it could be changed:
interface S {
readonly items: readonly string[];
}
const store = new Store<S>({items: []});
// this gives an error "splice does not exist on type ..."
store.update(draft => { draft.items.splice(1, 1) });
// with immer it works
declare const s: S;
produce(s, draft => { draft.items.splice(1, 1) });
This doesn't transpile as items is a readonly array. immer has a Draft type for this case - would be great if it could be used in pullstate:
https://github.com/lostpebble/pullstate/blob/master/src/Store.ts#L26 - https://github.com/lostpebble/pullstate/blob/master/src/Store.ts#L28
import { Draft } from "immer";
export type TUpdateFunction<S> = (draft: Draft<S>, original: S) => void;
type TPathReactionFunction<S> = (paths: TAllPathsParameter<S>, draft: Draft<S>, original: S) => void;
type TReactionFunction<S, T> = (watched: T, draft: Draft<S>, original: S, previousWatched: T) => void;
This is a great small library I just found, good work : ) There's a minor issue with TypeScript that would be great if it could be changed:
This doesn't transpile as items is a readonly array.
immerhas aDrafttype for this case - would be great if it could be used in pullstate:https://github.com/lostpebble/pullstate/blob/master/src/Store.ts#L26 - https://github.com/lostpebble/pullstate/blob/master/src/Store.ts#L28