Skip to content

Instantly share code, notes, and snippets.

@thedeeno
Created November 15, 2011 21:29
Show Gist options
  • Save thedeeno/1368415 to your computer and use it in GitHub Desktop.
Save thedeeno/1368415 to your computer and use it in GitHub Desktop.
Event doubling problem
# Models, Foo listens to Bar's 'create' event
class Bar extends Spine.Model
@configure "Bar"
class Foo extends Spine.Model
@configure "Foo"
constructor: ->
super
Bar.bind("create", @barCreated)
barCreated: (foo) =>
@trigger("update", this)
# Controller
class FooController extends Spine.Controller
constructor: ->
super
@count = 0
@foo.bind("update", @render)
render: =>
@count += 1
console.log(@count)
# main
$(document).ready ->
a = new Foo().save()
new FooController(foo: a)
# Here's the problem:
# The following line should trigger the below chain of events:
#
# Bar 'create' handled by Foo#barCreated
# Foo 'update' handled by FooItem#render
#
# it does, except Foo*upadate is triggered twice
# as evidenced by the following console output:
# => 1
# => 2
# which should have just been:
# => 1
#
# what gives? thoughts?
# debugger
new Bar().save()
@thedeeno
Copy link
Author

Interestingly, if I make Foo extend Spine.Controller instead of Model it works correctly. See this gist for the working example: https://gist.github.com/1368592

Leaning towards bug now.

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