Skip to content

Instantly share code, notes, and snippets.

@stevekane
Last active December 23, 2015 06:58
Show Gist options
  • Save stevekane/6597165 to your computer and use it in GitHub Desktop.
Save stevekane/6597165 to your computer and use it in GitHub Desktop.
CP of Object proxies that define a "view-specific" attribute
wrapWithProperty = (arrayName, propertyName, value) ->
Ember.computed arrayName + ".[]", ->
@get(arrayName).map( (each) ->
eachHash = {}
eachHash[propertyName] = value
eachHash.content = each
Ember.ObjectProxy.create(eachHash)
)
wrapWithHash = (arrayName, hashName) ->
Ember.computed arrayName = ".[]", hashName, ->
hash = @get(hash)
array = @get(arrayName)
array.map( (each) ->
hash.content = each
Ember.ObjectProxy.create hash
)
@mmun
Copy link

mmun commented Sep 17, 2013

Now with more O(1) inserts!

wrapWithProperty = (arrayName, propertyName) ->
  Ember.computed.map arrayName, (each) ->
    Ember.ObjectProxy.create
      content: each
      propertyName: null

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