0.1.2 • Published 6 years ago

omnistore v0.1.2

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

#omnistore

Immutable state for Preact using Immer

Purpose

Learning about constructing objects and creating js libraries. Its just another state management solution that may or may not be awful. I'm learning okay!.

I like the idea of having the mutation of the data in the same class/file that it is used for display. We will see how it goes. More of an experiment.

!!!API SUBJECT TO CHANGE!!!

Install

yarn add omnistore

Example

import { h, render } from 'preact'
import createStore from 'omnistore'

let { Subscribe, mutate } = createStore({
  count: 0
})

function increment() {
  mutate(state => {
    state.count++
  })
}

function decrement() {
  mutate(state => {
    state.count--
  })
}

function Counter() {
  return (
    <Subscribe on={state => state.count}>
      {count => (
        <div>
          <button onClick={decrement}>-</button>
          <span>{count}</span>
          <button onClick={increment}>+</button>
        </div>
      )}
    </Subscribe>
  )
}

render(<Counter />, window.root)

License

MIT License © Danny Lindquist

0.1.2

6 years ago

0.1.1

6 years ago