Skip to content

Instantly share code, notes, and snippets.

@rrcobb
Last active March 25, 2017 00:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rrcobb/380c123ff2d9a27ebd1ab39e02a2968e to your computer and use it in GitHub Desktop.
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
// 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