This package has been deprecated

Author message:

move to @the-/store ( https://github.com/the-labo/the/tree/master/packages/store#readme )

the-store

7.1.12 • Public • Published

the-store

Build Status npm Version JS Standard

Redux wrapper for the-framework

  • Simple wrapper of redux
  • Class base state management
  • Pseudo scoped state
  • Auto action-type generate
  • Load redux-devtools automatically

Installation

$ npm install the-store --save

Why This?

  • Reusing reducer logic with Class.
  • No need to care about ActionTypes.
  • Access to state with scope.
  • Full compatible with original redux

Usage

'use strict'
 
const theStore = require('the-store')
const {Scope} = theStore
 
// Scoped state class
class CounterScope extends Scope {
  // Define initial state
  static get initialState () {
    return 0
  }
 
  // Define reducer factory
  static get reducerFactories () {
    return {
      increment (amount) {
        return (state) => state + amount
      }
    }
  }
}
 
async function tryExample () {
  let store = theStore()
 
  // Create state instance and attach to the store
  store.load(CounterScope, 'counterA')
  store.load(CounterScope, 'counterB')
 
  {
    // Access to loaded store
    let {counterA} = store
 
    // Each instance has dispatcher methods which share signatures with reducerFactories
    // Invoking this method dispatches an action and reduce it into state
    // The action looks like { type: "counterA/increment", payload: [1] }
    counterA.increment(1)
 
    // Access to the scoped state
    console.log(counterA.state) // -> 1
  }
 
  // Store it self has all state
  console.log(store.state) // -> { counterA: 1 }
}
 
tryExample().catch((err) => console.error(err))
 

Usage

Nested Scopes

'use strict'
 
const theStore = require('the-store').default
const {ObjectScope, BooleanScope} = theStore
 
async function tryExample () {
  const store = theStore()
 
  // Create nested scope
  store.load(ObjectScope, 'scopeA')
  store.load(BooleanScope, 'scopeA', 'enabled')
 
  {
    const {scopeA} = store
 
    scopeA.set('foo', 'bar')
    scopeA.enabled.toggle(true)
 
    console.log(scopeA.enabled.state) // -> true
    console.log(scopeA.state) // -> { foo: 'bar' }
  }
 
  console.log(store.state) // -> { scopeA: { foo: 'bar'} , 'scopeA.enabled': true } }
}
 
tryExample().catch((err) => console.error(err))
 

API Guide

License

This software is released under the MIT License.

Links

Readme

Keywords

Package Sidebar

Install

npm i the-store

Weekly Downloads

1

Version

7.1.12

License

MIT

Unpacked Size

153 kB

Total Files

45

Last publish

Collaborators

  • okunishinishi