Promise based, co/koa-friendly prevalence component.
Think of it a super extensible, super fast, in-memory database that will restore it self from a history of commands.
Sample code
The sample code below two blog posts and then prints them, illustrating
- command registration via
register()
- command execution via
execute()
- querying via
query()
'use strict' let path = let co = let prevalence = let repo = var log = consolelog
Events
let repo =
Overview
Prevalence acts as a simple in-memory database with very controlled access patterns.
- Queries may inspect the data model (in parallel controlled by a read lock)
- Commands may alter the data model (serially controlled by a write lock)
- Commands must be described (with name and a handler) and invocations are logged with name and argument to a durable history (journal) so that the command can be re-executed on startup, thus restoring the model to the last known state.
- Results from queries and commands are by default serialized (i.e. deep copied), eliminating some nasty race conditions.
Check out wikipedia for a more formal definition of the prevalence pattern. Note that this implementation deviates on some key points. Most notably the support for snapshots is dropped.