Release Healer Man 0.1.29
This commit is contained in:
1 parent
8c9809d3e0
commit
544c1bee91
120 files changed
+4363
-1036
No files matched your search
@@ -0,0 +1,18 @@
|
||||
// Same vanilla store contract used by Zustand, without a React dependency on
|
||||
// the dedicated server. Each arena operation restores its own saved state.
|
||||
export function create<T>(initialize: (set: any, get: () => T, api: any) => T) {
|
||||
let state: T;
|
||||
const listeners = new Set<(state: T, previous: T) => void>();
|
||||
const api = {
|
||||
getState: () => state,
|
||||
setState(update: any, replace = false) {
|
||||
const previous = state;
|
||||
const patch = typeof update === "function" ? update(state) : update;
|
||||
state = replace ? patch : Object.assign({}, state, patch);
|
||||
if (state !== previous) for (const listener of listeners) listener(state, previous);
|
||||
},
|
||||
subscribe(listener: (state: T, previous: T) => void) { listeners.add(listener); return () => listeners.delete(listener); },
|
||||
};
|
||||
state = initialize(api.setState, api.getState, api);
|
||||
return api;
|
||||
}
|
||||
Reference in new issue
Block a user