Home Reference Source
import CommandMiddleware from 'dryadic/src/CommandMiddleware.js'
public class | source

CommandMiddleware

Executes command trees using registered middleware.

Middleware are functions that take two arguments: commandObject, context

Where commandObject may have multiple keys, and middleware may handle none or more of those keys. eg. the run middleware handles only the command key run

Constructor Summary

Public Constructor
public

constructor(middlewares: *[])

Member Summary

Public Members
public

Method Summary

Public Methods
public

call(commandRoot: Object, actionName: String, updateContext: Function): Promise

Each middleware is called with each command in a flattened depth-first stack.

public

use(middlewares: *)

Public Constructors

public constructor(middlewares: *[]) source

Params:

NameTypeAttributeDescription
middlewares *[]
  • optional
  • default: []

Public Members

public middlewares: * source

Public Methods

public call(commandRoot: Object, actionName: String, updateContext: Function): Promise source

Each middleware is called with each command in a flattened depth-first stack.

Any command that returns a Promise will be resolved, and the entire action (add, remove, update) is considered complete when all command results have resolved.

Params:

NameTypeAttributeDescription
commandRoot Object

The root command node of the tree as collected by DryadTree collectCommands. It contains pointers to the children.

actionName String

Each node has its context updated after success or failure as {state: {actionName: true|false[, error: error]}} On failure the error will also be stored here for debugging.

updateContext Function

supplied by the DryadPlayer, a function to update the context for a node.

Return:

Promise

resolves when all executed commands have resolved

public use(middlewares: *) source

Params:

NameTypeAttributeDescription
middlewares *