-
-
Save rrcobb/380c123ff2d9a27ebd1ab39e02a2968e to your computer and use it in GitHub Desktop.
The original, pure reflux store. http://fin.com/eng-blog/from-reflux-to-redux
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
// A pure reflux implementation of our search store | |
var Reflux = require('reflux'); | |
var SearchActions = require('./SearchActions'); | |
export default Reflux.createStore({ | |
listenables: [SearchActions], | |
init: function () { | |
this.setInitialData(); | |
}, | |
getInitialState: function() { | |
return this.DATA; | |
}, | |
setInitialData: function () { | |
this.DATA = { | |
searchValue: '', | |
selectedIndex: 0, | |
}; | |
}, | |
onSetInitialData: function () { | |
this.setInitialData(); | |
}, | |
onDeselectIndex: function() { | |
this.DATA.selectedIndex = -1; | |
this.trigger(this.DATA); | |
}, | |
onResetIndex: function() { | |
this.DATA.selectedIndex = 0; | |
this.trigger(this.DATA); | |
}, | |
onIncreaseIndex: function() { | |
this.DATA.selectedIndex += 1; | |
this.trigger(this.DATA); | |
}, | |
onDecreaseIndex: function() { | |
if(this.DATA.selectedIndex > 0) { | |
this.DATA.selectedIndex -= 1; | |
this.trigger(this.DATA); | |
} | |
}, | |
onChangeSearchValue: function (newValue) { | |
this.DATA.searchValue = newValue; | |
this.DATA.selectedIndex = 0; | |
this.trigger(this.DATA); | |
}, | |
onClearSearchInputs: function () { | |
this.DATA.searchValue = ''; | |
this.DATA.selectedIndex = 0; | |
this.trigger(this.DATA); | |
}, | |
}); | |
/////////////////////////////////////////////////////////// | |
// SearchActions.js | |
// The Reflux Actions for our search store | |
var Reflux = require('reflux'); | |
export default Reflux.createActions({ | |
changeSearchValue: {sync: true}, | |
clearSearchInputs: {sync: true}, | |
deselectIndex: {sync: true}, | |
setInitialData: {sync: true}, | |
resetIndex: {sync: true}, | |
increaseIndex: {sync: true}, | |
decreaseIndex: {sync: true}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment