MCPcopy Create free account
hub / github.com/drcmda/react-contextual / createStore

Function createStore

src/store.js:9–27  ·  view source on GitHub ↗
(state, id = uuid())

Source from the content-addressed store, hash-verified

7} from './context'
8
9export function createStore(state, id = uuid()) {
10 const result = {
11 id,
12 initialState: { ...state },
13 state,
14 subscriptions: new Set(),
15 context: createNamedContext(id),
16 destroy: () => {
17 removeNamedContext(id)
18 result.subscriptions.clear()
19 },
20 subscribe: callback => {
21 result.subscriptions.add(callback)
22 return () => result.subscriptions.delete(callback)
23 },
24 getState: () => result.state,
25 }
26 return result
27}
28
29function getStateUpdateFunctions(state) {
30 return Object.keys(state)

Callers 3

store.jsFile · 0.90
subscribe.jsFile · 0.90
constructorMethod · 0.85

Calls 2

createNamedContextFunction · 0.90
removeNamedContextFunction · 0.90

Tested by

no test coverage detected