1.0.5 • Published 6 years ago

lil-store v1.0.5

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

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

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago