Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created April 1, 2013 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgrove/5287853 to your computer and use it in GitHub Desktop.
Save rgrove/5287853 to your computer and use it in GitHub Desktop.
Super fast read-only fake Y.Model instance.
// Super fast read-only fake Model.
var GlobalEnv = YUI.namespace('Env.Model');
function LazyModel(config) {
this.data = Y.merge(config);
this.data.clientId || (this.data.clientId = this.generateClientId());
this.lists = [];
}
LazyModel.prototype = {
_isYUIModel: true,
addTarget: function () {
// noop
},
generateClientId: function () {
GlobalEnv.lastId || (GlobalEnv.lastId = 0);
return 'lazyModel' + '_' + (GlobalEnv.lastId += 1);
},
get: function (name) {
return this.data[name];
},
getAttrs: function () {
return Y.merge(this.data);
},
removeTarget: function () {
// noop
}
};
Y.LazyModel = LazyModel;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment