Created
November 15, 2011 21:29
-
-
Save thedeeno/1368415 to your computer and use it in GitHub Desktop.
Event doubling problem
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
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.