State API#

getState(path) โ‡’ T#

Grab a piece of data from state synchronously

Kind: global function

ParamType
pathstring

install()#

Bootstrap state stuff for Rebased

Kind: global function

resetState()#

Fully reset current fetch state

Kind: global function

setState(key, value, [options])#

Arbitrary way to set fetch state

Kind: global function

ParamTypeDefault
keystring
value*
[options]SetStateOptions{ cache: true }

unsetState(key, [options]) โ‡’ Promise.<void>#

Remove specific fetch state

Kind: global function

ParamTypeDefault
keystring
[options]Object{ cache: true }

applyDevTools([options]) โ‡’ compose#

Apply Redux DevTools full list of options at https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md

Kind: global function

ParamType
[options]*

connect(path, [options={#

context: false,
fetch: false

}]) โ‡’ Observable.<T>

Provides reactive data access through observables

Kind: global function

ParamType
pathstring

| [options={ context: false, fetch: false }] | Partial.<ConnectOptions> |

createAction(type) โ‡’ fn#

Helper for creating redux actions

Kind: global function

ParamType
typestring

Example

import { createAction, dispatch } from '@rebased/state';
// create action
const increment = createAction<number>('increment');
// dispatch
dispatch(increment(54))

createReducer(init, tree) โ‡’ fn#

Helper for creating redux reducers

Kind: global function

ParamType
initT
tree*

Example

import { createReducer } from '@rebased/state';
const person = createReducer<{
firstName: string;
lastName: string;
}>(
// initial state
{
firstName: 'John',
lastName: 'Doe',
},
// actions
{
setFirstName: (state, action) => {
state.firstName = action.payload;
},
setLastName: (state, action) => {
state.lastName = action.payload;
},
resetPerson: (state, action) => {
state.firstName = null;
state.lastName = null;
},
}
);

createStore(reducers, initialState, [enhancers])#

Create custom redux store

Kind: global function

ParamType
reducers*
initialState*
[enhancers]*

Example

import {
createStore,
createReducer,
applyDevTools,
applyMiddleware
} from '@rebased/state';
export const counter = createReducer(0, {
increment: (state, action) => state + action.payload,
decrement: (state, action) => state - action.payload
});
// logger middleware example
const logger = store => next => action => {
console.log('dispatching', action);
const result = next(action);
console.log('next state', store.getState());
return result;
};
createStore(
// list of reducers
{ counter },
// initial state
{ counter: 420 },
// composing enhancers
compose(applyDevTools({ production: false }), applyMiddleware(logger))
);
store().subscribe(it => console.log(it, store().getState()));

dispatch(action) โ‡’ any#

Action dispatcher

Kind: global function

ParamType
actionAction

store() โ‡’ RebasedStore#

Retrieve Rebased store instance

Kind: global function