Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Last active December 14, 2015 00:49
Show Gist options
  • Save mkuklis/5002179 to your computer and use it in GitHub Desktop.
Save mkuklis/5002179 to your computer and use it in GitHub Desktop.
flight asCollection mixin
'use strict';
define(
['./provider'],
function (provider) {
function AsCollection() {
var EVENT_TYPES = 'Add Remove Get Update Reset'.split(' ');
this.add = function (e, data) {
// TODO do stuff with your data provider
this.trigger(this.attr.name + ":dataAdded", data);
}
this.remove = function (e, data) {
this.trigger(this.attr.name + ":dataRemoved", data);
}
this.get = function (e, data) {
this.trigger(this.attr.name + ":dataGet", data);
}
this.update = function (e, data) {
this.trigger(this.attr.name + ":dataUpdated", data);
}
this.reset = function (e, data) {
this.trigger(this.attr.name + ":dataReset", data);
}
this.after('initialize', function () {
EVENT_TYPES.forEach(function (type) {
this.on(document, this.attr.name + ':request' + type, this[type.toLowerCase()]);
}, this);
});
}
return AsCollection;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment