Created
August 19, 2015 11:41
-
-
Save morlay/38faafe4aecff4a3a505 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 { 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