Skip to content

Instantly share code, notes, and snippets.

@slorber
Created December 9, 2014 19:02
Show Gist options
  • Select an option

  • Save slorber/a0a2728eb3dd08fe3072 to your computer and use it in GitHub Desktop.

Select an option

Save slorber/a0a2728eb3dd08fe3072 to your computer and use it in GitHub Desktop.
module.exports = AtomReact.newStore("currentSpace",{
handleEvent: function(event) {
switch (event.name) {
case AppEvents.Names.APPLICATION_STARTED:
var initialRouting = event.data.initialRouting;
this.selectSpace(initialRouting.selectedSpace);
break;
case AppEvents.Names.ROUTING_STATE_POPPED:
var routingState = event.data.routingState;
this.selectSpace(routingState.selectedSpace);
break;
case AppEvents.Names.SPACE_SELECTED:
if ( event.data.navigationName === NavigationUtils.MAIN_NAVIGATION ) {
this.selectSpace(event.data.selectedSpaceModel);
}
break;
case AppEvents.Names.CATEGORY_EDITION_UPDATED:
this.handleUpdatedCategory(event.data);
break;
}
},
handleUpdatedCategory: function (promise) {
var self = this;
promise.then(function (response) {
console.log(response);
self.storeCursor.follow("category").asyncSuccess().follow("name").set(response.name).done();
});
},
selectSpace: function(space) {
this.storeCursor.unset();
this.storeCursor.follow("space").set(space);
if ( space.type === SelectedSpaceModel.Types.CATEGORY ) {
this.storeCursor
.follow("category")
.setAsyncValue(CategoryRepository.getCategory(space.categoryId))
.done();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment