this.playerRowModel.model(data);
and get the error "models is not a function"
playerRowMap = new Model(data);
parseModel: function( data, xhr ) {
if (typeof data === 'string') {
return {
_id: data
};
}
var __v = data.__v,
_id = data._id;
if (_id && typeof __v === 'number' && Channel.store.hasOwnProperty(_id)) {
var channel = Channel.store[_id];
if (channel.__v > __v) {
delete data.__v;
delete data.userCount;
delete data.guestCount;
}
}
can.batch.start();
[
'moderators',
'bannedUsers',
'bootedUsers'
].forEach(function( key ) {
if (data.hasOwnProperty(key)) {
data[key] = User.models(data[key]);
}
});
if (data.owner) {
can.extend(data.owner, {
isModerator: true,
isOwner: true
});
data.owner = User.model(data.owner);
}
can.batch.stop();
return data;
},
isAdmin: {
get: function() {
var profile = this.attr('profile');
if (profile) {
return profile.attr('tier') === config.tiers.indexOf('admin');
}
return false
}
}
Changing profile / tier would recompute this. But if the value hasn't changed, computes dependent on this wouldn't recompute
var stache1 = new Date().getTime();
this.playerRowMap.attr({'player': request.player});
var stache2 = new Date().getTime();
pgatour.stacheTime += stache2 - stache1;
at the end of 156 updates the total accumulated time is 1.8 seconds
so… you click a button and expect new data to be shown, but it takes time
define('can/map/lazy/lazy', [
'can/util/util',
'can/map/lazy/bubble',
'can/map/map_helpers',
'can/map/map',
'can/list/list',
'can/map/lazy/nested_reference'
], function (can, bubble, mapHelpers) {
can.LazyMap = can.Map.extend({ _bubble: bubble }, {
setup: function (obj) {
this.constructor.Map = this.constructor;
this.constructor.List = can.LazyList;
this._data = can.extend(can.extend(true, {}, this._setupDefaults() || {}), obj);
can.cid(this, '.lazyMap');
this._setupComputedProperties();
var teardownMapping = obj && mapHelpers.addToMap(obj, this);
this._nestedReference = new can.NestedReference(this._data);
if (teardownMapping) {
teardownMapping();
}
can.each(this._data, can.proxy(function (value, prop) {
this.___set(prop, value);
}, this));
this.bind('change', can.proxy(this._changes, this));
},
_changes: function (ev, attr, how, newVal, oldVal) {
},
_addChild: function (path, newChild, setNewChild) {
var self = this;
this._nestedReference.removeChildren(path, function (oldChild, oldChildPath) {
bubble.remove(self, oldChild);
if (newChild) {
var newChildPath = oldChildPath.replace(path + '.', '');
if (path === newChildPath) {
oldChild._nestedReference.each(function (obj, path) {
newChild._nestedReference.make(path());
if (self._bindings) {
bubble.add(this, newChild, path());
}
});
} else {
var reference = newChild._nestedReference.make(newChildPath);
if (self._bindings) {
bubble.add(oldChild, newChild, reference());
}
}
}
});
if (setNewChild) {
setNewChild();
}
oldChild._nestedReference.each(
_nestedReference is null
require(‘can/map/lazy');
without installing can-map-lazy
theMap.bind(‘whatever.data.that.fails’, function() { … })
var template = can.stache('<player-row id="player-row-{{pid}}" {pid}="pid" {parent}="parent"></player-row>');
var fragment = template({
pid: this.pid,
parent: this
});