-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(store): use a custom implementation of redux
custom implementation can be easily optimized for performance and smaller library footprint
- Loading branch information
1 parent
9beed86
commit 131e843
Showing
3 changed files
with
37 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,6 @@ | |
"validate-commit-msg": "^2.8.0" | ||
}, | ||
"dependencies": { | ||
"redux": "^3.5.2", | ||
"window-or-global": "^1.0.1" | ||
} | ||
} |
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,36 @@ | ||
/** | ||
* Created by tushar.mathur on 05/09/16. | ||
*/ | ||
|
||
'use strict' | ||
|
||
const INIT = {type: '@@redux/INIT'} | ||
|
||
export class Store { | ||
constructor (reducer, state) { | ||
this.__reducer = reducer | ||
this.__state = state | ||
this.__listners = [] | ||
this.__dispatching = false | ||
this.dispatch(INIT) | ||
} | ||
|
||
subscribe (listener) { | ||
const i = this.__listners.push(listener) | ||
return () => this.__listners.splice(i - 1, 1) | ||
} | ||
|
||
getState () { | ||
return this.__state | ||
} | ||
|
||
dispatch (action) { | ||
if (this.__dispatching) return | ||
this.__dispatching = true | ||
this.__state = this.__reducer(this.__state, action) | ||
this.__listners.forEach(i => i(this.__state)) | ||
this.__dispatching = false | ||
} | ||
} | ||
|
||
export const createStore = (reducer, state) => new Store(reducer, state) |