diff --git a/README.md b/README.md index 6ecc320..4da1cb6 100644 --- a/README.md +++ b/README.md @@ -246,3 +246,9 @@ Creates the prototype for the web component element. | component.update | function | a redux reducer for updating component state. | | component.view | function | takes in the state and returns a dom tree. | + +### Show your support +⭐ this repo + +Would really appreciate if you could suggest improvements in docs. + diff --git a/docs/README.template.md b/docs/README.template.md index 4825c73..8b71ff6 100644 --- a/docs/README.template.md +++ b/docs/README.template.md @@ -228,3 +228,9 @@ update (state, {type, params}) { {{>main}} + +### Show your support +⭐ this repo + +Would really appreciate if you could suggest improvements in docs. + diff --git a/package.json b/package.json index c076547..d09316e 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,6 @@ "validate-commit-msg": "^2.8.0" }, "dependencies": { - "redux": "^3.5.2", "window-or-global": "^1.0.1" } } diff --git a/src/createWCProto.js b/src/createWCProto.js index 51c3efb..7571a98 100644 --- a/src/createWCProto.js +++ b/src/createWCProto.js @@ -6,7 +6,7 @@ */ 'use strict' -import {createStore} from 'redux' +import {createStore} from './micro-redux' import CustomEvent from './CustomEvent' function isArray (i) { diff --git a/src/micro-redux.js b/src/micro-redux.js new file mode 100644 index 0000000..3f7a4e0 --- /dev/null +++ b/src/micro-redux.js @@ -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)