Home Manual Reference Source Repository
import Stack from 'protonic/src/stack.js'
public class | source

Stack

A Stack isn't a stream, but can be used in conjunction with streams, actions, and transformers to make debugging much easier. Using pushAction, 'pushState,pushTransformer, andpushLog, you can create a log of state changes and their causes. Callingdump,dumpToLog, anddumpWhen` will give you control over when to view to stack.

Constructor Summary

Public Constructor
public

constructor(size: number, debug: boolean): Stack

constructor - A stack takes a size for the stack and a boolean to determine whether the stack should be enabled on creation.

Member Summary

Public Members
public

debug: *

public set

size(newSize: number): *

set size - sets the size of the stack.

public get

size: number: *

get size - getter for returning the current size of the stack.

Method Summary

Public Methods
public

dump(): Immutable.List

dump - Returns the stack, removing any undefined items.

public

dumpToLog(stateAccessor: array)

dumpToLog - When dumpToLog is called, it logs out the current stack to the console, formatting the different types of items in the stack for clarity.

public

dumpWhen(testFn: function, callbackFn: function)

dumpWhen - adds a test function to the stack that will run whenever new state is added to the stack.

public

pushAction(fnName: string, args: object)

pushAction - Adds an action to the stack.

public

pushLog(text: string)

pushLog - Adds a text log to the stack.

public

pushState(name: string, state: Immutable.Map, streamType: string)

pushState - Adds a state Map to the stack.

public

pushTransformer(fnName: string, args: object)

pushTransformer - Adds a transformer to the stack.

Public Constructors

public constructor(size: number, debug: boolean): Stack source

constructor - A stack takes a size for the stack and a boolean to determine whether the stack should be enabled on creation.

Params:

NameTypeAttributeDescription
size number

= 20 The size of the stack.

debug boolean

= false

Return:

Stack

Public Members

public debug: * source

public set size(newSize: number): * source

set size - sets the size of the stack.

public get size: number: * source

get size - getter for returning the current size of the stack.

Return:

number

returns size of the stack

Public Methods

public dump(): Immutable.List source

dump - Returns the stack, removing any undefined items.

Return:

Immutable.List

the stack.

public dumpToLog(stateAccessor: array) source

dumpToLog - When dumpToLog is called, it logs out the current stack to the console, formatting the different types of items in the stack for clarity. It takes an optional array for only logging a particular part of the state objects.

Params:

NameTypeAttributeDescription
stateAccessor array

takes an array of strings for logging only a certain part of the state

public dumpWhen(testFn: function, callbackFn: function) source

dumpWhen - adds a test function to the stack that will run whenever new state is added to the stack. The test function takes the state as an argument and returns a boolean. If the test function returns true, it will then run the callback function, passing the current stack as an argument.

Params:

NameTypeAttributeDescription
testFn function

takes state as an argument and returns a boolean.

callbackFn function

takes the current stack as an argument

public pushAction(fnName: string, args: object) source

pushAction - Adds an action to the stack.

Params:

NameTypeAttributeDescription
fnName string

Name of the action called.

args object

Arguments to the action called.

public pushLog(text: string) source

pushLog - Adds a text log to the stack.

Params:

NameTypeAttributeDescription
text string

The text to be added to the stack.

public pushState(name: string, state: Immutable.Map, streamType: string) source

pushState - Adds a state Map to the stack.

Params:

NameTypeAttributeDescription
name string

Name of the stream that's adding state

state Immutable.Map

The state object to add to the stack.

streamType string

The type of stream (View, Funnel, Stream) adding the state.

public pushTransformer(fnName: string, args: object) source

pushTransformer - Adds a transformer to the stack.

Params:

NameTypeAttributeDescription
fnName string

Name of the transformer called.

args object

Arguments to the transformer called.