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

DryadPlayer

Manages play/stop/update for a Dryad tree.

A Dryad has no state or functionality until it is played by a DryadPlayer. A Dryad can be played more than once at the same time by creating more DryadPlayers.

The DryadPlayer also holds the layers and command middleware which execute the functionality that the Dryads specify.

Constructor Summary

Public Constructor
public

constructor(rootDryad: *, layers: *, rootContext: {})

Member Summary

Public Members
public

classes: *

public

log: *

public
public

tree: *

Method Summary

Public Methods
public

addClass(dryadClass: Dryad)

Register a Dryad class so it can be located when used in hyperscript.

public

callCommand(nodeId: *, command: *): *

Execute a single command object for a single node using middleware outside the prepareForAdd/add/remove full tree command execution routine.

public

getClass(className: String): Dryad

Lookup Dryad class by name.

public

Get a representation of current state of the tree.

public

h(hgraph: Object): Dryad

Convert hyperscript graph to Dryad objects with registered classes

public

play(dryad: *): Promise

public

setRoot(dryad: Dryad)

Set a new tree.

public
public

updateContext(context: *, update: *): *

Allow a Dryad to update its own context.

public

use(layer: Object): *

Add a layer of functionality by registering Dryad classes and command middleware.

Public Constructors

public constructor(rootDryad: *, layers: *, rootContext: {}) source

Params:

NameTypeAttributeDescription
rootDryad *
layers *
rootContext {}
  • optional
  • default: {}

Public Members

public classes: * source

public log: * source

public middleware: * source

public tree: * source

Public Methods

public addClass(dryadClass: Dryad) source

Register a Dryad class so it can be located when used in hyperscript. Also needed if a class uses requireParent()

Params:

NameTypeAttributeDescription
dryadClass Dryad

public callCommand(nodeId: *, command: *): * source

Execute a single command object for a single node using middleware outside the prepareForAdd/add/remove full tree command execution routine.

This can be called out of band from a Dryad's add/remove method

Its for commands that need to be executed during runtime in response to events, streams etc. eg. spawning synths from an incoming stream of data.

Params:

NameTypeAttributeDescription
nodeId *
command *

Return:

*

public getClass(className: String): Dryad source

Lookup Dryad class by name.

Used by hyperscript and requireParent, this requires that layers and their classes were registered and any custom classes that you right are registered. If you aren't using hyperscript then you don't need to register your class.

Params:

NameTypeAttributeDescription
className String

case-insensitive

Return:

Dryad

public getDebugState(): * source

Get a representation of current state of the tree. Contains add|remove|prepared and may hold errors.

Return:

*

public h(hgraph: Object): Dryad source

Convert hyperscript graph to Dryad objects with registered classes

Params:

NameTypeAttributeDescription
hgraph Object

JSON style object

Return:

Dryad

public play(dryad: *): Promise source

Params:

NameTypeAttributeDescription
dryad *

Return:

Promise

that resolves to this

public setRoot(dryad: Dryad) source

Set a new tree.

Behavior while already playing is not yet defined.

Params:

NameTypeAttributeDescription
dryad Dryad

public stop(): Promise source

Return:

Promise

that resolves to this

public updateContext(context: *, update: *): * source

Allow a Dryad to update its own context.

Contexts are immutable - this returns a new context object.

Params:

NameTypeAttributeDescription
context *
update *

Return:

*

public use(layer: Object): * source

Add a layer of functionality by registering Dryad classes and command middleware.

Params:

NameTypeAttributeDescription
layer Object

.classes is a list of Dryad classes, .middleware is a list of middleware functions

Return:

*