apemanstore

Flux store for apeman


Keywords
apeman
License
MIT
Install
npm install apemanstore@4.0.1

Documentation

apemanstore

Build Status Code Climate Code Coverage npm Version JS Standard

apeman flavored redux store.

Installation

$ npm install apemanstore --save

Usage

'use strict'

const apemanstore = require('apemanstore')

apemanstore.define(
  (store, action) => {
    /* ... */
  }
).assign(
  {
    /* ... */
  }
)

const SignStore = apemanstore.define(
  // Define  reducer
  (state, action) => {
    switch (action.type) {
      case 'SET':
        return action.signed
      case 'DEL':
        return null
      default:
        return state
    }
  }
).assign(
  // Assign custom props.
  {
    setSign(signed) {
      const s = this
      s.dispatch({
        type: 'SET',
        signed: signed
      })
      return s
    },
    getSign() {
      const s = this
      return s.getState() || null
    },
    delSign() {
      const s = this
      s.dispatch({ type: 'DEL' })
      return s
    }
  }
)

let store = new SignStore({})

// Subscribe change
store.subscribe(() => {
  let sign = store.getSign()
  console.log(sign)
})

store.setSign({ id: 1 })

License

This software is released under the MIT License.

Links