Here's a simplified setup. The FilterBar contains six buttons. The button that is pressed is given the css class "active."
Last active
September 25, 2016 17:02
-
-
Save asdf072/caf760ea7e92508b8c4e824a259d6d15 to your computer and use it in GitHub Desktop.
React/Flux lag
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
var FilterActions = { | |
clickCatFilter: function(catId){ | |
Dispatcher.dispatch({ | |
actionType: FilterConst.CLICK_CAT_FILTER, | |
data: catId | |
}); | |
} | |
} |
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
var _filters = { | |
crews: [], | |
category: 'all', | |
taskType: null, | |
}; | |
var FilterStore = assign({}, EventEmitter.prototype, { | |
getAll: function(){ | |
return _filters; | |
}, | |
emitChange: function(){ | |
this.emit('change'); | |
}, | |
addChangeListener: function(callback){ | |
this.on('change', callback); | |
} | |
}); | |
Dispatcher.register(function(payload){ | |
switch(payload.actionType){ | |
case FilterConst.CLICK_CAT_FILTER: | |
var catId = payload.data; | |
// if re-clicking category, reset to all | |
_filters.category = (_filters.category == catId) ? 'all' : catId; | |
_filters.taskType = null; | |
FilterStore.emitChange(); | |
break; | |
} | |
}); |
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
var CrewtimeApp = React.createClass({ | |
render: function(){ | |
return ( | |
<div> | |
<div id="bottom-container"> | |
<FilterBar taskCats={taskCats} taskTypes={taskTypes} filters={this.state.filters} /> | |
</div> | |
</div> | |
); | |
}, | |
} |
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
var FilterBar = React.createClass({ | |
catButtonClick: function(catId){ | |
FilterActions.clickCatFilter(catId); | |
}, | |
render: function(){ | |
this.props.taskCats.sort(function(a,b){ | |
return a.display_order - b.display_order; | |
}); | |
var allCats = [{ | |
id: 'all', | |
name: 'All' | |
}].concat(this.props.taskCats); | |
var self = this; | |
return ( | |
<div id="filter-bar" className="navbar navbar-default"> | |
<div className="container-fluid"> | |
<ul className="nav navbar-nav"> | |
{allCats.map(function(cat){ | |
return <FilterButton category={cat} filters={self.props.filters} clickFunc={self.catButtonClick} key={cat.id} /> | |
})} | |
</ul> | |
</div> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment