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

View

Extends:

Stream → View

A View is a kind of Stream that is useful for transforming the shape of state for use in components or interfaces. A View caches the result of the function, and will only emit state to subscribers if the new return value is distinct from the previous value.

Constructor Summary

Public Constructor
public

constructor(source: Stream, viewFn: function): View

constructor - Takes a source stream, and transforms it through a function.

Method Summary

Public Methods
public

destroy - Clean up subscriptions.

Inherited Summary

From class Stream
public get

state: Immutable: *

get state - a getter for returning the current internal state of the Stream.

public set

state(newState: type): type: *

set state - a setter that's probably more clever than it needs to be. Instead of setting the internal state, it calls next.

stream.next(newState)
// is functionally the same as
stream.state = newState

Like I said, maybe too clever, but I thinks allow for a more delarative style when writing transformers.

public

forceState(state: Immutable.Map)

forceState - called when hydrating state from another source.

public

logStack(name: string, stack: Stack)

logStack - Adds a stack to automatically add state changes.

public

next(newState: Immutable)

next - Receives new state (externally, ideally through a transformer) and verifies that the new state is different from the Stream's current state before passing on to sendState (and, all the observers, by extension).

public

subscribe(observer: function): object

subscribe - takes a callback function that is executed any time the stream received new state.

Public Constructors

public constructor(source: Stream, viewFn: function): View source

constructor - Takes a source stream, and transforms it through a function. The view function takes state from the source stream and transforms it into returns a new shape of the state for use in a component or interface.

Override:

Stream#constructor

Params:

NameTypeAttributeDescription
source Stream

A stream to receive state from (can be a source stream or a funnel)

viewFn function

A function that takes state and returns a new shape for the state.

Return:

View

Public Methods

public destroy() source

destroy - Clean up subscriptions.