15.5.0 • Published 4 years ago

@the-/store v15.5.0

Weekly downloads
443
License
MIT
Repository
github
Last release
4 years ago

@the-/store

npm Version

Redux wrapper for the-framework

Installation

$ npm install @the-/store --save

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() {
  const store = theStore()

  // Create state instance and attach to the store
  store.load(CounterScope, 'counterA')
  store.load(CounterScope, 'counterB')

  {
    // Access to loaded store
    const { 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))

API Guide

See API Guide for more detail

License

This software is released under the MIT License.

Links

15.5.0

4 years ago

15.4.12

4 years ago

15.4.5

5 years ago

15.4.4

5 years ago

15.4.0

5 years ago

15.2.6

5 years ago

15.2.5

5 years ago

15.2.4

5 years ago

15.2.1

5 years ago

15.2.0

5 years ago

15.1.4

5 years ago

15.1.3

5 years ago

15.1.2

5 years ago

15.1.0

5 years ago

15.0.3

5 years ago

15.0.2

5 years ago