-
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
pipes | tanisha | ada trader #31
base: master
Are you sure you want to change the base?
Conversation
…successfully triggered event on form button click
…t upon click button
Ada TraderWhat We're Looking For
|
let formData = this.getFormData(); | ||
formData.buy = buy; | ||
const newOrder = new Order(formData); | ||
this.model.add(newOrder); |
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.
Right now you only have the symbol for this quote, since that's what you get when you read the form. However, in order to connect all the pieces, you really need the Quote
itself, not just the symbol. That will let the Order
listen to events on the quote, validate the initial buy/sell price, etc.
One way to do this would be for the OrderListView
to know about the QuoteList
collection, passing it in as an extra property to the constructor from app.js
. Then in QuoteList
you could write a function that, given a symbol, returns the corresponding quote.
}, | ||
buy() { | ||
this.model.set('buy', true); | ||
this.trigger('tradeUpdate', this); |
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'm not sure I like the attribute name buy
. A more descriptive way to go might be to call the attribute 'lastTradeType'
and set it to 'buy'
or 'sell'
.
Since the type of the most recent trade isn't really relevant for the quote, an even better strategy would be to not set it on the model at all, but provide it as an extra parameter when you trigger the event:
this.trigger('tradeUpdate', this, true);
And then the event listener in QuoteListView
:
trade: function(quoteView, buy) {
const tradeData = quoteView.model.toJSON();
tradeData.buy = buy;
const compiledTradeTemplate = this.tradeTemplate(tradeData);
// ...
}
Ada Trader
Congratulations! You're submitting your assignment!
Comprehension Questions
this.
before it.Usingthis
puts the jQuery selector in the context of that particular view. Without that context, the selector would be look through the entire project and so you would need to use ids to be more specific.