Martin I have come to prefer that my objects emit events rather than take callbacks in method invocations. Some benefits I have seen are:
- prevents nested callback spaghetti code - feels more like an interface (and therefore feels easier to unit test) Im sure there are some downsides, but Im relatively new to the language myself. -Rehan On Sunday, March 25, 2012 1:48:53 PM UTC-7, Martin Lundberg wrote: > > On Sunday, March 25, 2012 5:39:23 AM UTC+2, Rehan Iftikhar wrote: >> >> Hi Martin >> >> I was asking myself these very same questions about a year ago. What >> really helped me get my head around unit testing was to read Misko >> Hevery's guide to testable code: http://bit.ly/GNymAe. While the >> examples are in Java, the same principles apply: embrace the Single >> Responsiblity Principle (SRP), leverage Dependency Injection (DI), and >> isolate logic using Mock Objects. >> >> I test-drove an example of a UserAuthenticator class using these ideas >> here: http://bit.ly/GNmDeQ. I tried to emulate your dependencies as >> much as possible (UserRepository class). It uses Jasmine for the unit >> tests. You >> can use jasmine-node >> (https://github.com/mhevery/​jasmine-node<https://github.com/mhevery/jasmine-node>) >> >> to run >> these locally. >> >> -Rehan >> > > Hi Rehan! Thanks for the link and code, I'll definitely read throught the > guide by Misko Hevery and look through your code. I see that you use events > for almost everything, do you believe that you should use events as much as > possible instead of callbacks? > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
