Skip to content

Commit

Permalink
Merge pull request #17 from tusharmath/remove-redux
Browse files Browse the repository at this point in the history
Remove redux
  • Loading branch information
tusharmath committed Sep 5, 2016
2 parents 9beed86 + 42da104 commit bd2a546
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,9 @@ Creates the prototype for the web component element.
| component.update | <code>function</code> | a redux reducer for updating component state. |
| component.view | <code>function</code> | takes in the state and returns a dom tree. |


### Show your support
⭐ this repo

Would really appreciate if you could suggest improvements in docs.

6 changes: 6 additions & 0 deletions docs/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,9 @@ update (state, {type, params}) {


{{>main}}

### Show your support
⭐ this repo

Would really appreciate if you could suggest improvements in docs.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"validate-commit-msg": "^2.8.0"
},
"dependencies": {
"redux": "^3.5.2",
"window-or-global": "^1.0.1"
}
}
2 changes: 1 addition & 1 deletion src/createWCProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
'use strict'

import {createStore} from 'redux'
import {createStore} from './micro-redux'
import CustomEvent from './CustomEvent'

function isArray (i) {
Expand Down
36 changes: 36 additions & 0 deletions src/micro-redux.js
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)

0 comments on commit bd2a546

Please sign in to comment.