-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bianca Fernandez | Pipes | Ada Trader #24
base: master
Are you sure you want to change the base?
Conversation
Ada TraderWhat We're Looking For
|
}, | ||
cancel(event) { | ||
if (confirm("Are you sure?") === true){ | ||
this.model.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to call this.remove()
here, as we do in completeOrder()
.
What's currently happening is that we destroy the Order
model, which triggers update
on the OrderList
collection it was in, and that results in OpenOrderListView
calling its render()
function, which creates new OpenOrderView
instances for each order remaining in the collection. However, it does not get rid of the old view instances.
As a result, when we cancel an order it is no longer listed in the open orders list but the view does stick around in memory -- and it's still listening to the Quote
model for any updates. Thus, the cancelled order could still execute after it is no longer displayed. You can repro this by creating an order and clicking cancel immediately, then waiting until the relevant quote's price shifts enough that the cancelled order would have executed. You can see in the trade history that in fact the quote does get executed even after being cancelled.
// this.trades = []; // took this out because don't need to store this data anymore | ||
this.template = params.template; | ||
|
||
// this.listenTo(this.model, 'update', this.bind); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a slight change that could be made to sort of "combine" this line and the bind()
function below, to achieve the same result in a simpler way:
this.listenTo(this.model, 'trade', this.render);
The trick here is that while this.model
is referring to the QuoteList
collection, the way that Backbone works is that if any model inside of a collection triggers an event it "bubbles up" through the collection. So you can listen to the collection directly for any model-specific events, such as trade
.
A secondary benefit you get from this approach is that you don't need to call bind()
again if the collection of quotes is expanded.
Ada Trader
Congratulations! You're submitting your assignment!
Comprehension Questions