-
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
Amy Cash - Pipes - Ada Trader #41
base: master
Are you sure you want to change the base?
Conversation
Ada TraderWhat We're Looking For
|
@@ -7,11 +7,15 @@ const Quote = Backbone.Model.extend({ | |||
}, | |||
|
|||
buy() { | |||
// Implement this function to increase the price by $1.00 | |||
let buyPrice = this.get('price'); | |||
let newPrice = buyPrice + 1.00; |
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 could probably use const
here instead of let
.
let stringPrice = this.$(`#order-entry-form input[name=price-target]`).val(); | ||
orderData["targetPrice"] = parseFloat(stringPrice); | ||
orderData["buy"] = buy; | ||
this.bus.trigger('get_quote', this.model); |
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.
It looks like triggering this event isn't doing anything, because there are no objects that are listening for it.
this.quoteList.each((quote) => { | ||
if (orderData['symbol'] == quote.get('symbol') ) { | ||
orderData['quote'] = quote; | ||
} |
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.
This could also be written as:
orderData.quote = this.quoteList.findWhere({ symbol: orderData.symbol });
this.recordTrade(false) | ||
this.model.sell(); | ||
}, | ||
recordTrade(buy) { |
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 the logic in this function could be moved into the Quote
model, and have it be run as part of buy()
or sell()
.
This would allow it to be tested more easily, and reduces the coupling between this view and its model.
|
||
const quoteListView = new QuoteListView({ | ||
el: '#quotes-container', | ||
model: quoteList, |
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.
By passing quoteList
here we are creating a view for a collection of quotes that is not connected to the simulator at all (and thus there appears to be no automatic change in prices).
If we insted write model: quotes,
for this line then we'll be connecting this QuoteListView
to the same collection of quotes as the simulator receives, which should solve the issue.
Ada Trader
Congratulations! You're submitting your assignment!
Comprehension Questions