Hacker News new | ask | show | jobs
by gedy 3952 days ago
I see 2-way data-binding is mentioned here and will still be supported (good). Curious why has 2-way now become 'uncool' recently, e.g. React? 2-way is what got me excited about client side JS due to the code reduction in an average app. Is just that Angular 1's implementation was non-performant? (lots of other frameworks use it as well, e.g. Knockout, RactiveJS, etc).
2 comments

Two way data binding is awesome and neat and shiny and chrome. It's also pretty slow; a lot of pragmatic angular work involves keeping the number of watchers firing during digest cycles minimized. If you have a lot of data that's all two-way-bound by default, but aren't making any use of the bindings, that's a lot of wasted cycles. I mean, my app has a lot of data in it, stuff like {{username}} which rarely ever changes in the model, so I don't really need two-way binding for it.

What I like here is that one-way binding is the default, and you can do two-way stuff if needs be, because sometimes it really is the best call.

I think two-way binding going by the way side because developers are tired of having to deal with unintended loop backs. You start having to add weird flags to your data to indicate that data changes were the result of user actions and not changes from the backend to avoid endless event loops. Two-way binding results in more code that's buggier whereas one-way binding with actions results in much more organized and understandable code with none of the unintended consequences.
I'm thinking that's a framework-specific or coding-style issue? From using a number of frameworks, I've virtually never had issues with endless loops. Perhaps it helps that frameworks like Knockout, etc don't trigger change events when the value is the same.
> Two way data binding is awesome and neat and shiny and chrome. It's also pretty slow;

No it's not, Angular's implementation of two way data binding is slow; dirty checking is what's slow.

{{username}} is a one-way-binding. Two-way-binding happens only with ng-model and = on isolate scopes.
This seems to be the new standard in JS framework development. Ember, Angular and React have all switched to making "data down, actions up" be their M.O., while still supporting 2-way data binding if you want or need it.
Thanks. Yeah 1-way as default is reasonable. I suppose in my case I haven't seen performance issues due to data size, and also have taken to using RactiveJS which allows both 1-way and 2-way via [[someProp]] and {{someProp}}, respectively.
Two way bindings are awesome for demos.

They tend to introduce a fair amount of unnecessary complexity in real world applications. Especially if you have to deal with changes that don't happen in real time or intermediate states or two different formats of presentation for the same data.

The workaround for two way bindings in React is relatively easy compared to the kind of hoops you have to jump through when you start with two way bindings and have to backtrack because of pesky real world requirements.