RXA
An lib to create an application which is based on React + Redux + Rxjs + Ramda + Reselect. It supports developer to build React app faster.
Cool features:
- Support auto prefetch components
- Support lazy module loading, dynamic actions
- No reducer needed
- Support async redux action
- Simple action dispatching
- Auto applying reselect to improve app rendering performance
- Auto load/save app state using localStorage
Examples:
- Hello world
- Prefetchable component
- Auto load/save app state
- Todo list
- $async usage
- Free drawing component
- Dots game
- Huge Form (200 inputs)
- Form and react-select
Hello world
import React from "react";import render from "react-dom";import create from "rxa"; // create app with intial stateconst app = // register hello action ; // create connectionconst helloButtonConnect = app; const HelloButton = ; ;
Prefetchable component
import React from "react";import render from "react-dom";import create from "rxa"; // create app with intial stateconst app = ; const userInfoConnect = app; // create user info componentconst UserInfo = ; const userInputConnect = app; // create user input componentconst UserInput = ; ;
Auto load/save app state
import React from "react";import render from "react-dom";import create from "rxa"; // create app with intial stateconst app = // register hello action ; // create connectionconst counterConnect = app; const Counter = ; ;
API References:
- create
- app.action
- app.actions
- app.autoSave
- app.connect
- app.debounce
- app.dispatch
- app.getState
- app.invoke
- app.Provider
- app.reducer
- app.selector
- app.subscribe
create
create(initialState: object): app
Create new application with initial state
create(localStorageKey: string, defaultState: object): app
Create new application and load state from localStorage with give key. If nothing loaded, defaultState will be used
app.action
app.action(statePropAndActionName: string, action: function): app
Register new action. Action result will update to given state property name automatically. Supports object property path
app.action(stateProp: string, action: function, actionName: string): app
Register new action with specified actionName. Action result will update to given state property name automatically. Supports object property path
app.action(stateProp: string, action: function, options: ActionOptions): app
Register new action with specified options. Action result will update to given state property name automatically. Supports object property path. Available options:
- single: bool For async action only. Action only executes once at the same time. The previous execution will be stopped if there is new execution.
- dispatchStatus For async action only. Will dispatch executing status of this action when it is changed (loading, success, fail...).
app;
Instead of returning a partial state object directly, an action can return a function that takes action collection. Action collection contains margin actions ($state, $current, $done, $fail, $success)
appaction'test' { const $state $current $done $fail $success $async = actions; ; // get current state ; // get current state prop value ; // execute callback once current action done ; // execute callback once current action success ; // execute callback once current action fail return ;}; For $async magic action see <a href="https://codesandbox.io/s/8klzr8q558">$async usage</a>
app.actions
app.actions(actionModel: object): app
Register multiple actions at once
app;
app.autoSave
app.autoSave(): app
Enable auto save with default options
app.autoSave(localStorageKey: string): app
Enable auto save with specified localStorageKey
app.autoSave(options: object): app
Enable auto save with an options. Available options:
- key: string localStorage key to be used for saving app state
- debounce: number specific debounce time to delay saving
app.connect
app.connect(propsMapper: (state, actions) => object): ReduxConnection
Create Redux Connection with specified propsMapper
app.connect(propsMapper: (state, actions) => object, prefetch: () => Promise: ReduxConnection
Create Redux Connection with specified propsMapper and specific prefetch action.
app.connect(propsMapper: (state, actions) => object, prefetchArgsSelector: (props) => prefetchArgs, prefetch: prefetchArgs => Promise): ReduxConnection
Create Redux Connection with specified propsMapper and specific prefetch action. prefetchArgsSelector will be called to select args for prefetch action
See Prefetchable component for usage.
app.debounce
app.debounce(func: function, delay: number)
Create debounced function wrapper with specified delay time
app.dispatch
app.dispatch(action): app
Call redux store.dispatch(action)
app.getState
app.getState(): state
Call redux store.getState()
app.invoke
app.Provider
Return binded Redux Provider
app.reducer
app.reducer(reducer: function)
Register redux reducer for special purpose
app.selector
app.selector(...args): Selector
Call reselect.createSelector(...args)
app.subscribe
app.subscribe(state => any): Subscription
Adds a change listener. It will be called any time an action is dispatched, and some part of the state tree may potentially have changed