UNPKG

zustand

Version:

🐻 Bear necessities for state management in React

36 lines (33 loc) 1.17 kB
System.register([], (function (exports) { 'use strict'; return { execute: (function () { const createStoreImpl = (createState) => { let state; const listeners = /* @__PURE__ */ new Set(); const setState = (partial, replace) => { const nextState = typeof partial === "function" ? partial(state) : partial; if (nextState !== state) { const previousState = state; state = replace ? nextState : Object.assign({}, state, nextState); listeners.forEach((listener) => listener(state, previousState)); } }; const getState = () => state; const subscribe = (listener) => { listeners.add(listener); return () => listeners.delete(listener); }; const destroy = () => listeners.clear(); const api = { setState, getState, subscribe, destroy }; state = createState( setState, getState, api ); return api; }; const createStore = exports('default', (createState) => createState ? createStoreImpl(createState) : createStoreImpl); }) }; }));