@drschwabe/stack

A command driven middleware stack for managing control flow / application state

Renamed to stack-core.
Last updated 3 years ago by drschwabe .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @drschwabe/stack 
SYNC missed versions from official npm registry.

Stack

Stack is a route driven state management library that leverages the familiar callback and middleware pattern used in Express.

Install

npm install --save @drschwabe/stack

Usage

var stack = require('stack')

stack.on('/do-something', (state, next) => {
   //modify state here, then pass it along: 
   next(null, state)
})

stack.fire('/do-something')

Unlike Express however, instead of http requests the idea is to pass your entire application's state through your 'stack' of listeners. Each execute in order, asynchronously, passing along the modified state via next()

The main benefit to this approach is the set of 'commands' (ie: routes) your application now inheritently exposes; essentially an API you can tap into from anywhere, including from modules you later introduce or from outside contributors who can standardize around your stack as the formal way to extend and create new functionality in your app.

API

stack.on(command, callback)
Creates a listener that invokes callback on the given command

stack.fire(command, state, callback)
Fires an arbitrary command causing the stack of listeners listening to that command to fire (in order) until the end of the stack.

Properties

stack.state
The last known state of the stack. Persists after a fire concludes; after the bottom of the stack is reached hence the updated state is retained and available to subsequent fires.

stack.state._command
A special property added to your state object to keep track of the current command being issued. Analogous to req.parms in Express.

stack.state._command[parameter]
Any number of parameters on the command itself (ie: /do-something/:time are made available as a property of the stack.state._command object (ie: stack.state._command.time).

License

MIT

Current Tags

  • 2.0.0                                ...           latest (3 years ago)

1 Versions

  • 2.0.0 [deprecated]           ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |