7.1.12 • Published 5 years ago

the-store v7.1.12

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

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

7.1.12

5 years ago

7.1.11

5 years ago

7.1.10

5 years ago

7.1.9

5 years ago

7.1.7

5 years ago

7.1.6

5 years ago

7.1.5

5 years ago

7.1.4

5 years ago

7.1.3

5 years ago

7.1.2

5 years ago

7.1.1

6 years ago

7.1.0

6 years ago

7.0.15

6 years ago

7.0.14

6 years ago

7.0.13

6 years ago

7.0.12

6 years ago

7.0.11

6 years ago

7.0.10

6 years ago

7.0.9

6 years ago

7.0.8

6 years ago

7.0.7

6 years ago

7.0.6

6 years ago

7.0.5

6 years ago

7.0.4

6 years ago

7.0.3

6 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.0.7

6 years ago

6.0.6

6 years ago

6.0.5

6 years ago

6.0.4

6 years ago

6.0.3

6 years ago

6.0.2

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.5.1

6 years ago

5.5.0

6 years ago

5.4.8

6 years ago

5.4.7

6 years ago

5.4.6

6 years ago

5.4.4

6 years ago

5.4.3

6 years ago

5.4.2

6 years ago

5.4.1

6 years ago

5.4.0

6 years ago

5.3.1

6 years ago

5.3.0

6 years ago

5.2.1

6 years ago

5.2.0

6 years ago

5.1.3

6 years ago

5.1.2

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.4.9

6 years ago

4.4.8

6 years ago

4.4.6

6 years ago

4.4.5

6 years ago

4.4.4

6 years ago

4.4.3

6 years ago

4.4.2

6 years ago

4.4.1

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.0

6 years ago

4.0.4

6 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.4.2

7 years ago

3.4.1

7 years ago

3.4.0

7 years ago

3.3.3

7 years ago

3.3.2

7 years ago

3.3.1

7 years ago

3.3.0

7 years ago

3.2.7

7 years ago

3.2.6

7 years ago

3.2.5

7 years ago

3.2.4

7 years ago

3.2.3

7 years ago

3.2.2

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.6

7 years ago

3.0.5

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago