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]
}
})