A few days ago I posted a solution to create a custom money binding for knockout.js. If you recall, I was a bit hesitant about the solution because I felt that it wasn't very semantic. Namely, DOM objects do not have a
money property to bind to. I had a chat with Elijah Manor and he shared the same reservations. Comments on that post echoed the yucky feeling. Time for round 2.
What I had missed was the writable dependentObservable introduced in knockout.js some time recently. With this new found power I can keep the appropriate
value bindings and still have a clean view model. With the solution above, I don't have to jump through hoops to get a clean json representation of my view model. On top of that, my bindings are still simple enough to understand. There is less magic and I like it that way.
This feels a lot better than the first solution. I'm still not sold though. It feels like this type of concern should be pushed out of the view model. Possibly something like this?
<input data-bind="value:Cash" data-convert="value:MoneyConverter" />
What do you think of the new bits? Is this a better or worse solution? Also, how can we improve this?