Skip to content

Instantly share code, notes, and snippets.

@brianjmiller
Created October 12, 2011 21:14
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 brianjmiller/1282603 to your computer and use it in GitHub Desktop.
Save brianjmiller/1282603 to your computer and use it in GitHub Desktop.
toJSON and mlClass attribute properties
// use as follows (can be combined)
{
ATTRS: {
total: { value: 0, toJSON: false },
lines: { value: null, setter: '_setML', mlClass: Y.App.Manage.ML.Lines }
}
}
// base class definition
YUI.add(
"custom-manage-m-base",
function (Y) {
Y.Base._ATTR_CFG.concat("toJSON");
Y.Base._ATTR_CFG_HASH.toJSON = true;
Y.Base._ATTR_CFG.concat("mlClass");
Y.Base._ATTR_CFG_HASH.mlClass = true;
var Clazz = Y.namespace("App.Manage.M").Base = Y.Base.create(
"custom_manage_m_base",
Y.Model,
[],
{
_setML: function (list, name) {
Y.log(Clazz.NAME + "::_setML: " + name);
var existing_list = this.get(name);
if (existing_list) {
return existing_list.reset(list);
}
var ml_class = this._getAttrCfg(name).mlClass;
Y.log(Clazz.NAME + "::_setML - creating new list");
var new_list = new ml_class (
{
bubbleTargets: this
}
);
new_list.reset(list);
return new_list;
},
toJSON: function () {
Y.log(Clazz.NAME + "::toJSON");
var attrs = Clazz.superclass.toJSON.apply(this, arguments);
Y.each(
attrs,
function (v, k, o) {
var attr_cfg = this._getAttrCfg(k);
if (Y.Lang.isValue(attr_cfg.toJSON) && ! attr_cfg.toJSON) {
delete attrs[k];
}
},
this
);
return attrs;
}
},
{
ATTRS: {}
}
);
},
"0.0.1",
{
requires: [
"model"
]
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment