Last active
December 14, 2015 18:38
-
-
Save tomshaw/5130483 to your computer and use it in GitHub Desktop.
Generic object extending Backbone events.
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
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