Function
Static Public Summary | ||
public |
createAction(getRunner: function(emit: function): function): function Creates an observable function that invokes the nested inner function. |
|
public |
createStore(options: Object): Store Dynamically extends Store and instantiates the new class. |
|
public |
createSubscriber(component: React.Component): React.Component 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
.
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.
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:
Name | Type | Attribute | Description |
component | React.Component | the component to wrap |
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);