SMH110 / widgets

1 stars 0 forks source link

Calculator's addNumber method is factory function without good reason #23

Closed massimocode closed 8 years ago

massimocode commented 8 years ago

When writing the initial tests for the calculator, I noticed that the API for addNumber was a bit horrible.

For example calculator.addNumber(5)()... instead of calculator.addNumber(5)

It's inconsistent with the APIs for the other methods, for example calculator.addPlus() and calculator.equal().

The reason it's like this is because of the front end click bindings data-bind="click: addNumber(5)". The addNumber(5) call must return a function to be executed by the click handler.

We could remove this responsibility from the calculator and put it inside the binding if we rewrote the binding like this data-bind="click: addNumber.bind(null, 5)". That would mean our test code would then be calculator.addNumber(5), which is a lot better.

massimocode commented 8 years ago

This has been fixed in https://github.com/SMH110/My-Calculator/pull/27. Awaiting code review and merge.