Skip to content

Instantly share code, notes, and snippets.

@denisraslov
Last active January 7, 2018 17:37
Show Gist options
  • Save denisraslov/46e8ef1c67b1269f4d528ad4c4a0adc5 to your computer and use it in GitHub Desktop.
Save denisraslov/46e8ef1c67b1269f4d528ad4c4a0adc5 to your computer and use it in GitHub Desktop.
import { getStore } from 'react/store';
const Task = Backbone.View.extend({
listenToStore() {
const taskId = this.taskId;
const store = getStore();
// Listen to changes of the Redux store
store.subscribe(() => {
const state = store.getState();
const storeTaskData = state.tasks[taskId];
// Compare if data is changed.
// Because the task reducer in Redux returns a new task object everytime.
if (storeTaskData !== this.model.attributes) {
// Set the changed data to the model
this.model.set(storeTaskData);
// And re-render
this.render();
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment