Fastflux Home Reference Source Repository

Function

Static Public Summary
public

Creates an observable function that invokes the nested inner function.

public

createStore(options: Object): Store

Dynamically extends Store and instantiates the new class.

public

Higher-order component that automatically subscribes to ObservableState props.

Static Public

public createAction(getRunner: function(emit: function): function): function source

import {createAction} from 'fastflux/core/action'

Creates an observable function that invokes the nested inner function.

The inner function may call emit.

Params:

NameTypeAttributeDescription
getRunner function(emit: function): function

Return:

function

Example:

let mul = createAction(emit => function (x, y) {
  emit(x * y)
});
mul.subscribe(result => console.log("Result:", result));

//> Result: 25
mul(5, 5);

public createStore(options: Object): Store source

import {createStore} from 'fastflux/core/store'

Dynamically extends Store and instantiates the new class.

options.getInitialState and either options.reducer or options.reducers are required.
When both are defined, options.reducers takes precedence.
Type requirements are interchangable, meaning either can take Object or function.

Params:

NameTypeAttributeDescription
options Object
options.getInitialState function(): Any<S>
options.reducer function(state: Any<S>, message: Message): Any<S>
options.reducers Object

maps Message#type to reducers

Return:

Store

Example:

let counter = createStore({
  getInitialState() { return 0 },
  reducers: {
    inc(state) { return ++state },
    dec(state) { return --state }
  }
})

public createSubscriber(component: React.Component): React.Component source

import {createSubscriber} from 'fastflux/core/subscriber'

Higher-order component that automatically subscribes to ObservableState props.

Params:

NameTypeAttributeDescription
component React.Component

the component to wrap

Return:

React.Component

Example:

let text = new ObservableState("Foo");

class Label extends React.Component {
  render() {
    return <div>{this.props.text}</div>;
  }
}
Label = createSubscriber(Label);

// Render <Label> with text "Foo"
React.render(<Label text={text} />, mountPoint);

// After 1 second change text to "Bar"
setTimeout(() => text.emit("Bar"), 1000);