{"comment":{"created_at":"2011-10-20T18:58:42Z","body":"In other words: don't like the idea of polluting the binding namespace...","updated_at":"2011-10-20T18:58:42Z","url":"https://api.github.com/repos/SteveSanderson/knockout/issues/comments/2472813","id":2472813,"user":{"avatar_url":"https://secure.gravatar.com/avatar/7c110e6606bd4751a3261998ac6e6ee7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"7c110e6606bd4751a3261998ac6e6ee7","url":"https://api.github.com/users/rosenfeld","id":32246,"login":"rosenfeld"}},"action":"created","issue":{"number":180,"created_at":"2011-10-20T18:16:13Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"Suppose a boolean observable:\r\n\r\n    viewModel.myBoolean = ko.observable(false)\r\n\r\nI want myBoolean() to return false, but want data-bind=\"text: myBoolean\" to use \"No\" instead.\r\n\r\nNot sure what would be the best way to design this API, but here are some alternatives:\r\n\r\n    ko.observable(false).extend(myBooleanFormatter)\r\n\r\nmyBooleanFormattter could introduce a new \"formatted\" function to do the job. The convention in the views would be to call any formatted() method on the observable if the method exists, instead of calling toString() in the value of the observable.\r\n\r\nFor simplifying this, an option could be:\r\n\r\n    ko.observable(false).formatter(myBooleanFormatter)\r\n\r\nwhere myBooleanFormatter would get the raw value and return a string representation.\r\n\r\nThis would allow me to have clean views using data-bind=\"text: myBoolean\" instead of data-bind=\"text: myBoolean().formatted()\".\r\n\r\nDoes it make sense?","comments":5,"title":"Add support for formatted observables","updated_at":"2011-10-20T18:58:42Z","url":"https://api.github.com/repos/SteveSanderson/knockout/issues/180","id":2007642,"assignee":null,"milestone":null,"closed_at":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/7c110e6606bd4751a3261998ac6e6ee7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"7c110e6606bd4751a3261998ac6e6ee7","url":"https://api.github.com/users/rosenfeld","id":32246,"login":"rosenfeld"},"html_url":"https://github.com/SteveSanderson/knockout/issues/180","labels":[],"state":"open"},"legacy":{"issue_id":2007642,"comment_id":2472813}}