Created
April 25, 2014 16:34
-
-
Save publickeating/11295500 to your computer and use it in GitHub Desktop.
array_controller+proxy_items.js
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
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; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?