Skip to content

Instantly share code, notes, and snippets.

@acuros
Created April 24, 2014 13:12
Show Gist options
  • Save acuros/11254131 to your computer and use it in GitHub Desktop.
Save acuros/11254131 to your computer and use it in GitHub Desktop.
var Page = {
contextFetchers: {
},
runContextFetchers: function(eventName) {
var contextFetchers = this.contextFetchers[eventName] || [];
var context = this;
var names = [];
$.each(contextFetchers, function(idx, callback) {
if($(names).filter(function(idx, obj){return callback.name == obj}).length !== 0) {
return;
}
names.push(callback.name);
var response = callback() || {};
$.each(response, function(key, value) {
context[key] = value;
})
});
},
registerContextFetcher: function(eventName, contextFetcher) {
var fetchers = this.contextFetchers[eventName] || [];
fetchers.push(contextFetcher);
this.contextFetchers[eventName] = fetchers;
}
};
var Page1 = {};
var Page2 = {};
$.extend(Page1, Page);
$.extend(Page2, Page);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment