lil-store

1.0.5 • Public • Published

lil-store

My naive approach to create a state management library.

Inspired by Redux, Vuex and Flux architecture.

Install

npm install lil-store

How to use

In all seriousness, just read the code. It's less than 30 lines!

const { createStore } = require('./index')
 
const reducer = (store, action, payload) => {
  if (!store) store = 0 // this is how you define your initial state
 
  switch(action) { // define how your state will change according to action
    case 'incr':
    store++
    break
    case 'decr':
    store--
    break
    case 'add':
    store += payload
    break
  }
 
  return store
}
 
const store = createStore(reducer)
 
store.subscribe(state => console.log(state))
 
store.commit('add', 5) // prints out 5
store.commit('incr') // prints out 6
store.commit('incr') // prints out 7
store.commit('decr') // prints out 6

In Browser

Through UNPKG:

<script src="https://unpkg.com/lil-store"></script>

An object named lilStore is exposed to the global Window object.

You can then access createStore like so:

<script>
var createStore = lilStore.createStore;
</script> 

Why

State management is not a React/Vue only need!

This library (more like code snippet) allows you to easily create a reactive store for whatever needs you have!

Roadmap

  • Export module for browser use
  • Publish that to unpkg.com or something
  • Add tests
  • Implement TravisCI
  • Implement code coverage

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i lil-store

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

3.48 kB

Total Files

3

Last publish

Collaborators

  • poyu