Skip to content
shaunpersad edited this page Aug 26, 2017 · 13 revisions

Installation

npm install redu

API

Redu is comprised of just two functions: createStore(Component), and createSubscriber(Component, toProps).


createStore(Component: React.Component): StoreComponent

Creates and returns a StoreComponent wrapped around the supplied Component.

StoreComponent

A React.Component that wraps another, and houses your application-level state. Because it is simply a regular React component, you have access to all the usual React component API's (e.g. StoreComponent.defaultProps), in addition to the following provided by Redu:

-StoreComponent.initialState: Object

Setting this property with an object will provide the StoreComponent with its initial state. The StoreComponent's state will be made available to SubscriberComponents via the toProps function.

-StoreComponent.actions: Object

Setting this property with an object of functions will provide the StoreComponent with action functions that will be bound to the StoreComponent instance when it is created. These actions will be made available to SubscriberComponents via the toProps function.

-StoreComponent.WrappedComponent: React.Component

This property will return the Component that was wrapped by createStore(Component). It is not directly settable.


createSubscriber(Component: React.Component, toProps: function): SubscriberComponent

Creates and returns a SubscriberComponent wrapped around the supplied Component.

toProps(storeState: Object, storeProps: Object, storeActions: Object): Object

Gives you access to the StoreComponent's state, props, and actions. It must return an object, which will be passed into the SubscriberComponent as props.

SubscriberComponent

A React.Component that wraps another, and can derive props from its ancestor StoreComponent's state, props, and action functions. Similar to StoreComponent, it also has the following:

-SubscriberComponent.WrappedComponent: React.Component

This property will return the Component that was wrapped by createSubscriber(Component, toProps). It is not directly settable.


Next: Basic Example