2.2.3 • Published 5 years ago

opstore v2.2.3

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

opstore

An immutable operator-based state container for JavaScript.

npm install opstore

build status coverage status npm version

Features

  • Single source of truth. Data is stored in a single, immutable atom.
  • Composable. Keep sizes small and roll your own store by only bundling the operators you need.
  • Extensible. Add your own operators and middleware.
  • Observable. Subscribe to partial and/or every state change.
  • Message-driven. Every operation is dispatched internally as a message, which enables such things as logging and event sourcing by way of middleware.
  • Typed. Written in TypeScript.

Motivation

opstore was built to make it easier to build “vanilla” web apps. Being able to listen to state changes in certain part of the state tree, makes it possible to create tiny render cycles that are simple to reason about and perform well.

This project is based on ideas from Redux, Redis, Firebase and Yr’s source code.

Usage

Out of the box

import {createStore} from 'opstore'

const store = createStore({count: 0})
const countRef = store.ref('count')

countRef.subscribe(count => console.log(count))

console.log(countRef.get()) // 0

countRef.incr() // 1
countRef.incr() // 2
countRef.decr() // 1
countRef.decr() // 0

Composing a store

import {createFactory, lpush, lremi} from 'opstore'

const createStore = createFactory({lpush, lremi})

const store = createStore({
  todos: []
})

const todosRef = store.ref('todos')

todosRef.subscribe(todos => console.log(JSON.stringify(todos)))

console.log(JSON.stringify(store.get())) // []
todosRef.lpush({title: 'A'}) // [{"title":"A"}]
todosRef.lpush({title: 'B'}) // [{"title":"A"},{"title":"B"}]
todosRef.lremi(0) // [{"title":"B"}]

Documentation

See API Documentation.

License

MIT © Marius Lundgård

2.2.3

5 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago