mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-02 20:21:19 +02:00
feat: make zustand store logic ready for classes
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
import produce from "immer";
|
||||
import produce, { immerable } from "immer";
|
||||
import create from "zustand";
|
||||
|
||||
function immer(config) {
|
||||
return function(set, get, api) {
|
||||
return config(fn => set(produce(fn)), get, api);
|
||||
const obj = config(
|
||||
fn =>
|
||||
set(() =>
|
||||
produce(get(), state => {
|
||||
fn(state);
|
||||
})
|
||||
),
|
||||
get,
|
||||
api
|
||||
);
|
||||
obj[immerable] = true;
|
||||
return obj;
|
||||
};
|
||||
}
|
||||
|
||||
function createStore(store) {
|
||||
store = store.new ? store.new.bind(store) : store;
|
||||
return create(immer(store));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user