Skip to content

Instantly share code, notes, and snippets.

@publickeating
Created April 25, 2014 16:34
Show Gist options
  • Save publickeating/11295500 to your computer and use it in GitHub Desktop.
Save publickeating/11295500 to your computer and use it in GitHub Desktop.
array_controller+proxy_items.js
SC.ArrayController.reopen({
proxyItem: null,
indexOf: function (object, startAt) {
var content = this._scac_observableContent();
if (this.proxyItem) {
object = object.get('content');
}
return content ? content.indexOf(object, startAt) : -1;
},
objectAt: function (index) {
var content = this._scac_observableContent(),
ret = null,
item;
if (content) {
item = content.objectAt(index);
if (item && this.proxyItem) {
ret = this.proxyItem(item);
ret.set('content', item);
} else {
ret = item;
}
}
return ret;
}
});
@dcporter
Copy link

Thanks for this. IMO the proxyItem should be a class which conforms to a protocol (with a quack) and which retains a reference to the originating ArrayController.

Should the proxy items be retained, with new content items swapped into them when membership of the content array changes? Or should they be retained and kept with the same content item as long as possible?

In other words, what should happen when things change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment