Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created January 6, 2012 14:20
Show Gist options
  • Select an option

  • Save timruffles/1570806 to your computer and use it in GitHub Desktop.

Select an option

Save timruffles/1570806 to your computer and use it in GitHub Desktop.
Simple list viewmodel
ListView = (el) ->
views = []
["pop","shift"].each (method) =>
@[method] = ->
remove = views[method]()
el.removeChild remove.el
[["unshift","prepend"],["push","append"]].each ([array,dom]) =>
@[array] = (view) ->
views[array](view)
byModelId[view.model.id] = view
$(el)[dom](view.el)
@size = ->
views.length
this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment