Realt is a new way to work with Redux inspired by Alt
If you want to skip the docs and jump straight to the code, you should check out /examples folder, there you'll find some of Redux examples migrated to realt
npm install --save realt
import { createAction } from 'realt';
const addText = createAction('addText');
expect(addText.toString()).toEqual('ADD_TEXT');
expect(addText('Hello world')).toEqual({
type: 'ADD_TEXT',
payload: 'Hello world'
});
import { createActions } from 'realt';
const actions = createActions(['create', 'delete']);
import { createActions } from 'realt';
const actions = createActions({
create(id) {
return id;
},
update(id, data) {
return { id, data }
}
});
import { createActions } from 'realt';
class Actions {
constructor() {
this.generate(
'create'
);
}
update(id, data) {
return { id, data };
}
}
const actions = createActions(Actions);
You can use this method in ActionsClass constructor, it'll setup actions which simply pass forward all incoming data
Note: all of the generated actions will receive only 1 parameter, so your data should be wrapped in an object
import { createReducer } from 'realt';
const initialState = [{
id: 0,
title: 'Use Realt',
}];
const reducer = createReducer({
create(state, id) { // or handleCreate/reducerForCreate
},
update(state, id) { // or handleUpdate/reducerForUpdate
}
}, initialState);
import { createReducer } from 'realt';
import actions from '../actions';
class Reducer {
constructor() {
this.bindAction(actions.create, this.handleCreate);
this.bindHandler(this.handleDelete, actions.delete);
}
get initialState() {
return [{
id: 0,
title: 'Use Realt',
}];
}
handleCreate(state, id) {
return state.concat({ id, title: 'New entity' });
}
handleDelete(state, id) {
return state.filter(entity => entity.id !== id);
}
}
export default createReducer(Reducer);
Here you must bring an initial snapshot of your view's state
This method is a bridge between your reducer and certain action type. When you call it, you're connecting the data flow from some action right into the store