Skip to content

Instantly share code, notes, and snippets.

@morlay
Created August 19, 2015 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save morlay/38faafe4aecff4a3a505 to your computer and use it in GitHub Desktop.
Save morlay/38faafe4aecff4a3a505 to your computer and use it in GitHub Desktop.
import { createStore } from 'reflux';
import GalleryActions from '../actions/GalleryActions'
export default createStore({
init(){
this.galleryMap = {}
this.listenTo(GalleryActions.listGalleries.completed, 'onGalleryListUpdate')
this.listenTo(GalleryActions.getGallery.completed, 'onGalleryUpdate')
},
onGalleryListUpdate(galleryList){
galleryList.forEach(this.setGallery, this)
this.trigger()
},
onGalleryUpdate(gallery){
this.setGallery(gallery)
this.trigger()
},
setGallery(gallery){
if (gallery.id) {
this.galleryMap[gallery.id] = gallery
}
},
getGalleryById(galleryId){
return this.galleryMap[galleryId]
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment