mware-ts
mware-ts
is an extension to mware
but for Typescript, with an async/await style middleware stack.
Usage
;; ; // add middlewareuse; use; // run stackrune, 7, 5.thenconsole.log'fin'; // returns [e, [7, 13]]
Using Event
;; ; // add middlewareuse; // run stackrune, 'continue'.thenconsole.loge.isDefaultPrevented; // falserune, 'prevent'.thenconsole.loge.isDefaultPrevented; // true
Errors
;; // error middlewareuse; // runrunnew Event'test'.catchconsole.errorerr; // [Error: Bad stuff!]
Installation
NPM
npm install --save mware-ts
Yarn
yarn add mware-ts
API
mware()
Returns a mware
instance.
Event
Must be instanciated and passed as #run
first parameter.
Usage: new Event(string)
Event objects have preventDefault()
and isDefaultPrevented()
methods.
Instance
#use(fn: Function)
fn: Function
, Async middleware functions to add to stack.
#run(e: Event, ...args: any[])
e: Event
, Instance ofEvent
class.args: *
, Arguments to pass to each middleware function.
Returns a promise.
License
Copyright (c) 2016 Station