Skip to content

Instantly share code, notes, and snippets.

@jedschneider
Created May 24, 2012 14:10
Show Gist options
  • Select an option

  • Save jedschneider/2781772 to your computer and use it in GitHub Desktop.

Select an option

Save jedschneider/2781772 to your computer and use it in GitHub Desktop.
ServiceRequest = Backbone.Model.extend
initialize: (attrs) ->
# Is there a simple way to extract this pseudo-model functionality
# into a superclass?
_.bindAll @, 'set_line_items',
@bind('change', @set_line_items)
@set_line_items()
set_line_items: ->
if(@attributes.line_items and not(@line_items instanceof LineItemList))
@line_items = new LineItemList(new LineItem(li) for li in @attributes.line_items)
@line_items.bind 'change', => @trigger 'change'
# more line item events bound here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment