Skip to content

Commit

Permalink
Adds es module support info to README.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoferjoseph committed Jul 6, 2018
1 parent 0a2c29a commit 26a7a54
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,32 @@ Minimal unidirectional data flow utility library.

## Install

##### node

`npm i redeux --save`

##### OR
##### script

[`<script src="redeux.umd.js"></script>`](https://github.com/kristoferjoseph/redeux/blob/master/example.html)

##### es module

`import Redeux from 'https://unpkg.com/redeux?module'`

## Usage

#### reducer

this is what a reducer looks like

```js

// State machine lib
var switcher = require('hash-switch')

// Default state
var initialState = []

// Create a state machine
var stateMachine = switcher({
// Each action type maps to a function for changing data
'ADD': add
},
// If no constant match is found we just return the current state
function (state) {
return state
})

// By defualt the reducer function's name
// By defualt the reducer function's name property
// will be used as the key for the data atom
// NOTE: You can also add the `key` property to your reducer function
// i.e.: `todos.key = todos` useful for when you want to use uglify and mangle is changing function names.
module.exports = function todos (state, action) {
// Guard against undefined action
action = action || {}
Expand All @@ -63,8 +57,13 @@ module.exports = function todos (state, action) {
// by initializing with initial state
state = state || initialState

// Call the state machine with the action type constant, the current state, and the action data.
return stateMachine(type, state, data)
switch (type) {
case 'ADD':
return add(state, data)
break;
default:
return state;
}
}

// The add function will get passed the current state and the action data
Expand Down

0 comments on commit 26a7a54

Please sign in to comment.