3. Code Flags
• Use global state
• Use static methods
• Mix object construction with business logic
• Mixing find-what-i-need logic with business logic
• Write LONG functions
• Use many conditionals
• Dependency hell
• Long inheritance hierarchies
22. Data / DOM
Business logic
JS
write
read
(event handlers)
DOM API
HTMLDivElement
23. Event Handlers
• Get the data
• Call testable handler function
$('#username').on('input', function() {
var newValue = this.value;
self.checkUsername(newValue);
});
25. Non Mixed Version
function Toggle(pages) {
var active = 0;
function toggle() {
pages[active].hide();
active = (active + 1) % pages;
pages[active].show();
}
pages[0].show();
return toggle;
}
$('#btn').on('click', Toggle([$('#page1'), $('#page2')]));
27. Testing Non-Mixed Version
• Inject and test
var toggle = Toggle([p1, p2]);
expect(p1.visible).to.be.true;
expect(p2.visible).to.be.false;
toggle();
expect(p1.visible).to.be.false;
expect(p2.visible).to.be.true;
28. Mixing Lookups
• Separate lookup code from business logic
• Test interesting parts -> business logic
41. Code Flags
• Use global state
• Use static methods
• Mix object construction with business logic
• Mixing find-what-i-need logic with business logic
• Write LONG functions
• Use many conditionals
• Dependency hell
• Long inheritance hierarchies