Last active
December 14, 2015 00:49
-
-
Save mkuklis/5002179 to your computer and use it in GitHub Desktop.
flight asCollection mixin
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
'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