-
-
Save jgcmarins/8a9f4ea7d0d44dc2bd457eadabfc10cc to your computer and use it in GitHub Desktop.
Revisions
-
kristoferjoseph revised this gist
Apr 10, 2019 . 2 changed files with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
kristoferjoseph revised this gist
Apr 10, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ store.subscribe(state => console.log(state)) -
kristoferjoseph created this gist
Apr 10, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ store.mutate(state => state.thing = { id: 'yolo' }) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ const listeners = [] const state = {} let noop = x => x function subscribe (fn) { listeners.push(fn) } function unsubscribe (fn) { listeners.splice(listeners.indexOf(fn), 1) } function mutate (mutation) { mutation = mutation || noop let i = 0 let l = listeners.length let fn mutation(state) for (i; i < l; i++) { fn = listeners[i] fn(state) } } function merge (o, n) { for (let prop in n) { o[prop] = n[prop] } } function store (initialState) { if (initialState) { merge(state, initialState) } return state } store.subscribe = subscribe store.unsubscribe = unsubscribe store.mutate = mutate export default store