Skip to content

Instantly share code, notes, and snippets.

@tomshaw
Last active December 14, 2015 18:38
Show Gist options
  • Save tomshaw/5130483 to your computer and use it in GitHub Desktop.
Save tomshaw/5130483 to your computer and use it in GitHub Desktop.
Generic object extending Backbone events.
define('AppLoad', ['jquery', 'underscore', 'backbone', 'AppConfig', 'ProjectCollection', 'PhotographyCollection'], function ($, _, Backbone, AppConfig, ProjectCollection, PhotographyCollection) {
var AppLoad = _.extend({}, Backbone.Events);
AppLoad.GDRIVE_LOADED = 'GDRIVE_LOADED';
AppLoad.projectCollection = null;
AppLoad.photographyCollection = null;
AppLoad.totalLoaded = 0;
AppLoad.requiredLoaded = 2;
AppLoad.start = function () {
var $this = this;
$this.projectCollection = new ProjectCollection();
$this.projectCollection.url = AppConfig.URL_PROJECTS;
$this.projectCollection.fetch({
success: function (model, response) {
return $this.onLoad();
}
});
$this.photographyCollection = new PhotographyCollection();
$this.photographyCollection.url = AppConfig.URL_PHOTOGRAPHY;
$this.photographyCollection.fetch({
success: function (model, response) {
return $this.onLoad();
}
});
};
AppLoad.onLoad = function () {
this.totalLoaded++;
if (this.totalLoaded === this.requiredLoaded) {
console.log('trigger event: ' + this.totalLoaded);
return this.trigger(AppLoad.GDRIVE_LOADED);
}
};
return AppLoad;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment