-
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
<Ada-Trader><Pipes><Roxanne Agerone> #47
base: master
Are you sure you want to change the base?
Conversation
…uyquote from order and listener in quote
Ada TraderWhat We're Looking For
This is a good start. You were able to get a lot of the core functionality working, which is no mean feat. However, there's definitely room for improvement here, particularly around building a clean design for an event-driven program. From my reading, most of your trouble seems to come from an over-reliance on the event bus. I suspect that you started working with the bus before quite understanding what problem it's supposed to solve and so ended up using it for everything, even when it made your design much more complicated. As they say, when you've got a shiny new hammer everything starts to look like a nail. Knowing when not to use an event bus (letting components know about and listen to each other) or when not to use events at all (direct function calls) is just as important as knowing how to use one. As one concrete example of this, let's talk about your workflow for adding a limit order. To create a limit order, we need to do a few things:
In your code, this begins in The first two steps, listening for the click event and reading the form data, are well done. Finding the quote that corresponds to the symbol is where things start to get messy. Your code triggers an event on the bus, which is handled in the The reason event handling doesn't work well here is that you need to invoke some behavior and see the result - in this case, find the quote for a given symbol. With a direct function call you would use a return value, but event handlers don't have a way to return a value to whatever triggered the event. This means you need a complex system of reciprocal events to get the information where you need it. A cleaner design might be to:
Note that we don't use the bus at all - we've replaced one event sequence with a direct function call, and the other with listening to the specific component we're interested in. Event driven programming is not an easy topic to master, but it's an essential tool for a modern software engineer, especially in an asynchronous context like front-end JavaScript. Keep studying and thinking about it, and let me know if you'd like to sit down together and work through some revisions to this code. |
uniqueQuoteSymbols(){ | ||
// this.$('#quotes').empty(); | ||
let quoteSymbols = []; | ||
this.model.each((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 function doesn't do any view-specific things. To me this means it's probably in the wrong place - perhaps it would be better as a function of QuoteList
. This would probably simplify your event handling chain as well.
// dropdownElement.html(''); | ||
// console.log(event); | ||
// console.log('this is event'); | ||
// event.forEach( (symbol) => { |
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 I like the idea of putting this function here. I would take it a step further and, instead of building it as an event handler, call it directly from $(document).ready()
with the list of symbols (or an instance of QuoteList
).
this.dropdownTemplate = params.dropdownTemplate; | ||
this.listenTo(this.hamRadio, 'render_order_dropdown', this.renderOrderDropdown); | ||
this.listenTo(this, 'order_purchase', this.addLimitOrder); | ||
this.listenTo(this, 'order_sell', this.addLimitOrder); |
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.
As far as I can tell, you don't have any code to trigger order_purchase
or order_sell
events.
src/views/limit_order_view.js
Outdated
addQuoteAttribute(quoteModel){ | ||
if(!this.quoteModel){ | ||
debugger; | ||
} |
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 function is redefined below - you should remove this version of it.
Ada Trader
Congratulations! You're submitting your assignment!
Comprehension Questions