leopold
__^___
[(0¿0)]
~-
Event-sourced models for nodejs or browser
Install
npm install --save leopold
Quick Start
Eventable models
// create a leo that includes a unit of work and factory for event providersconst leo = const accountSpec = const customerSpec = //use let customer = customerSpeccustomer // -> customer.accounts['checking']customer // -> account.balance === 300.42
Notice we have a object graph that is two deep.
Now let's consume a set of events to restore state to where this was
let instance = customerSpeclet events = event: 'initialized' id: 1 name: 'mike' event: 'accountApproved' id: 1 name: 'checking' event: 'initialized' id: 'checking' name: 'checking' balance: 0 event: 'deposited' id: 'checking' balance: 30042let envelope = revision: 1 events: events // events are stored as envelopesreturn leo // instance.accounts[{cuid}].balance === 300.42
Taking advantage of events for testing side effects
// create a leo that includes a unit of work and factory for event providersconst envelopes = const storage = { envelopes}const leo = const myModel = myModelenvelopeslength === 1 // trueenvelopes0events0event === ‘initialized’ // true
Dependencies
leopold
uses stampit under the hood
and the eventable
call presumes you are composing event source behavior
into an prototype ('spec').
leopold
is also using some ES6 features that require babel.
Running tests
make test
(nodejs)
make browser
(browser) then visit on any browser at http://localhost:2222