3.0.0 • Published 3 years ago

state-manager-object v3.0.0

Weekly downloads
18
License
MIT
Repository
github
Last release
3 years ago

State Manager Object

State management module with event subscription and different kind of stores.

NPM npm version npm bundle size npm

Install

npm i state-manager-object

Use

A simple numeric store:

const {NumericStore} = require('state-manager-object')

const initialState = 0 // which is default
const store = new NumericStore(initialState)

store.increment()
store.increment()
store.decrement()

store.get() === 1

An object store:

const {ObjectStore} = require('state-manager-object')

const initialState = {age: 10}
const store = new ObjectStore(initialState)

store.update({age: 11})
store.update({name: 'Abc'})

store.get() === {age: 11, name: 'Abc'}

Generic store:

const {Store} = require('state-manager-object')

const initialState = 'something'
const store = new Store(initialState)

store.update('some other thing')
store.update(9)

store.get() === 9

All store types has a reset method which reverts state to its initial state:

store.reset()

store.get() === initialState

Listen for changes:

store.subscribe(function(currentState, prevState) {
  // do something on state change
})

Comparison is being done based on === operator when new state update request received.


Version management of this repository done by releaser 🚀


Thanks for watching 🐬

ko-fi

3.0.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago