forked from nanostores/nanostores
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref nanostores#171 Here's initial attempt to move all stores state into global context object. Context is basically a listeners queue and a map of stores states. Context management api is still yet to explore. For now it's for internal usage now.
- Loading branch information
Showing
6 changed files
with
86 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
let createContext = () => { | ||
let context = { | ||
// listener queue | ||
q: [], | ||
// store states | ||
s: new Map(), | ||
} | ||
return context; | ||
} | ||
|
||
let context = createContext() | ||
|
||
export let getListenerQueue = () => { | ||
return context.q | ||
} | ||
|
||
// lazily initialize store state in context | ||
export let getStoreState = (store) => { | ||
let state = context.s.get(store) | ||
if (!state) { | ||
state = { | ||
// listeners | ||
ls: [], | ||
// listeners count | ||
lc: 0, | ||
// value | ||
v: store.iv, | ||
} | ||
context.s.set(store, state) | ||
} | ||
return state | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters