Last active
January 7, 2018 17:37
-
-
Save denisraslov/46e8ef1c67b1269f4d528ad4c4a0adc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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