1.0.14 • Published 5 years ago

stoor.js v1.0.14

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

A tiny drop-in 🛸 jsonschema statemanager / datastore for javascript

Usage

Output:

updated: ABC
ABC
ABC
{type:'string', default:'foo'}

This library is handy to act as the 'heart' for battletested javascript UI-frameworks which are written programmatically (dom-style). Rewriting that in React/Vuejs would be too expensive compared to simply using it with a functional store.

NOTE: you can put stores into stores recursively 😎 like so:

store.bar( new Stoor({
    apples:{ type:"number", default:1},        
}))
store.bar().apples(5) // increment apples

Features

  • tiny portable library (code fits on one screen)
  • jsonschema initialisation (to generate forms later on using json-form e.g.)
  • typesafe checks (extendable with tv4 using middleware for jsonschema v4-support)
  • sync + async access: store.data.foo returns store.foo() while bypassing middleware+listeners

Use standalone in the Browser

Dont like transpilers? No worries:

<script src="https://unpkg.com/stoor.js"></script>
<script>
    var store = new Stoor({...})
</script>

Listeners

var off = store.foo( (v) => {
    // react on change        
})
off() // delete listener

Middleware

Property-specific:

store.foo.use( (e,v,next) => {
    if( e == 'update' ){ ... }          // triggered when value is updated
    if( e == 'read'   ){ ... }          // triggered when value is being read ( `store.foo()` )
    if( e == 'bless'  ){ ... }          // custom
    next(v)                             // continue (async) middleware
})
store.foo.trigger('bless', new Date())  // trigger custom event

Store-specific:

store.use( (e,v,next) => {
    if( e == 'bless'  ){ ... }          // custom
    next(v)                             // continue (async) middleware
})
store.trigger('bless', new Date())

Reason

  • selfstudy in portable & dependency-free javascript
  • needed something jsonschema-, framework-agnostic-, async+sync ish for an existing codebase
  • sometimes converting a codebase to react/vuejs is too expensive

Credits

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago