#Backbonex
Backbone -> Redux Redux -> Backbone
Allow use your Models and Collections listen action and syncronize changes in a redux state tree
npm install --save backbonex
Create your state tree of backbone models or Collections
const backboneTree = {
post,
posts
};
If you desire you can createInitialState from current Backbone entities using createInitialState
.
import {createInitialState} from 'backbonex';
const backboneState = createInitialState(backboneTree);
import backbonex from 'backbonex';
const duxCreateStore = backbonex(createStore, applyMiddleware);
const store = duxCreateStore(backboneTree, backboneState, [...middlewares]);
import {emitter} from 'backbonex';
import {POST_CHANGE_ATTRIBUTES} from './actions/post';
class Post extends Backbone.Model {
static initialize() {
emitter.on(POST_CHANGE_ATTRIBUTES, (action)=> {
this.set(action.payload.attributes);
});
}
}
import {POST_CHANGE_ATTRIBUTES} from './actions/post';
export function postChangeAttr(attributes) {
return {
type: POST_CHANGE_ATTRIBUTES,
attributes
};
}