{"action":"created","issue":{"url":"https://api.github.com/repos/aurelia/binding/issues/353","repository_url":"https://api.github.com/repos/aurelia/binding","labels_url":"https://api.github.com/repos/aurelia/binding/issues/353/labels{/name}","comments_url":"https://api.github.com/repos/aurelia/binding/issues/353/comments","events_url":"https://api.github.com/repos/aurelia/binding/issues/353/events","html_url":"https://github.com/aurelia/binding/issues/353","id":142421062,"number":353,"title":"Value converters should support triggering updates","user":{"login":"thomas-darling","id":6388663,"avatar_url":"https://avatars.githubusercontent.com/u/6388663?v=3","gravatar_id":"","url":"https://api.github.com/users/thomas-darling","html_url":"https://github.com/thomas-darling","followers_url":"https://api.github.com/users/thomas-darling/followers","following_url":"https://api.github.com/users/thomas-darling/following{/other_user}","gists_url":"https://api.github.com/users/thomas-darling/gists{/gist_id}","starred_url":"https://api.github.com/users/thomas-darling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomas-darling/subscriptions","organizations_url":"https://api.github.com/users/thomas-darling/orgs","repos_url":"https://api.github.com/users/thomas-darling/repos","events_url":"https://api.github.com/users/thomas-darling/events{/privacy}","received_events_url":"https://api.github.com/users/thomas-darling/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aurelia/binding/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-21T17:46:47Z","updated_at":"2016-05-24T07:12:46Z","closed_at":null,"body":"Ok, so here we go...\r\n\r\n### Background\r\n\r\nI understand the concept of binding behaviors, and think they are a really great idea for things like throttling binding updates - for that stuff they make a lot of sense. However, the more I work with this, the more I find myself wrapping a value converter in a binding behavior, just to make sure it updates when the user changes site settings such as locale or currency.\r\n\r\nThe `TBindingBehavior` in the Aurelia i18n library is a perfect example of this:\r\nhttps://github.com/aurelia/i18n/blob/master/src/t.js\r\n\r\nNow, we are a large, global site and unfortunately we found the Aurelia i18n library to be quite insufficient for our needs - that's a topic for another discussion that I would love to have with you guys, but the point is that we are working on a custom library for this, and in doing that, we need to implement a number of custom value converters to handle formatting of things like currencies, dates, times, numbers, percentages, pluralization, lists, prepositions, word variants, and lots of other crazy stuff.\r\n\r\nThe problem is, every single one of those converters need to be wrapped in a corresponding binding behavior, as it needs to update whenever the locale or currency is changed. Actually, I can't think of very many uses for value converters where such a requirement would not be present - after all, their fundamental purpose is to convert values to/from their view representation, and that will almost always be a localized string.\r\n\r\nI feel like this workaround is an abuse of the binding behavior concept, as what we're doing here feels much more like a value conversion than like a behavioral change. And if every converter has to be wrapped in a behavior anyway, then why even have the distinction? It just blurs the line between the two concepts, and ultimately makes it a bit of a mess.\r\n\r\n### Proposal\r\n\r\nThe way I see it, binding behaviors should be used only for things like throttling binding updates or setting things like `oneWay` or `oneTime` - uses where they actually modify the fundamental behavior of the *binding*. Meanwhile, value converters should have a way to signal to the underlying binding that it needs to update - it does not need to have full access to the actual binding instance, it just needs some way to signal to the binding that it needs to update... or maybe even simpler, just a property that we can specify, which lists the signals that should trigger an update (you can think of it as just stating dependencies on signals, just like the constructor states dependencies on services, etc.)\r\n\r\nExample:\r\n\r\n```typescript\r\nexport class CurrencyValueConverter\r\n{\r\n    // When the framework instantiates the binding converter, it should look for this property,\r\n    // and if present, it should subscribe the binding to the specified signals.\r\n    signals = ['currency-changed', 'locale-changed'];\r\n    ...\r\n}\r\n```\r\n\r\nThis would make this whole thing so much nicer and more intuitive to work with, and I think it would make the distinction between the two concepts much more clear."},"comment":{"url":"https://api.github.com/repos/aurelia/binding/issues/comments/221185197","html_url":"https://github.com/aurelia/binding/issues/353#issuecomment-221185197","issue_url":"https://api.github.com/repos/aurelia/binding/issues/353","id":221185197,"user":{"login":"thomas-darling","id":6388663,"avatar_url":"https://avatars.githubusercontent.com/u/6388663?v=3","gravatar_id":"","url":"https://api.github.com/users/thomas-darling","html_url":"https://github.com/thomas-darling","followers_url":"https://api.github.com/users/thomas-darling/followers","following_url":"https://api.github.com/users/thomas-darling/following{/other_user}","gists_url":"https://api.github.com/users/thomas-darling/gists{/gist_id}","starred_url":"https://api.github.com/users/thomas-darling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomas-darling/subscriptions","organizations_url":"https://api.github.com/users/thomas-darling/orgs","repos_url":"https://api.github.com/users/thomas-darling/repos","events_url":"https://api.github.com/users/thomas-darling/events{/privacy}","received_events_url":"https://api.github.com/users/thomas-darling/received_events","type":"User","site_admin":false},"created_at":"2016-05-24T07:12:45Z","updated_at":"2016-05-24T07:12:45Z","body":"Any update on this? We're really looking forward to it :-)"}}
{"actor":{"display_login":"thomas-darling"}}