notwaldorf / ama

:raising_hand: Ask @notwaldorf anything!
94 stars 13 forks source link

Google's recommended data flow convention- official examples do not show the recommended convention #80

Closed dman777 closed 6 years ago

dman777 commented 6 years ago

At my new job with our Polymer project, I am trying to pass on the discipline of using one way bindings for downward data flow and events for upwards data flow from Data Flow in Polymer Elements and Apps (Polymer Summit 2016).

But I don't see this practice in Google examples where this convention is followed.... for example... the blog app and the shop app. They use 2 way binding instead of using events for the upward data flow.

Should I be using this data flow as recommended? And if so, why don't the official example apps use this data flow convention?

Also, when should I use 2 way binding instead of events for upward data?

notwaldorf commented 6 years ago

As a side note, this is my personal AMA, not a Polymer issues repo. I left it here for people wanted to ask me questions, not because they wanted another channel to get tech support. This question would've been best asked on the shop app, for example, since it's literally about shop (and not my life).

There's a bit of history in between that talk and shop and that is: shop was written before that talk. From building that app, the team learnt a couple of things (like the fact that two-way data bindings are hard to reason about), and that's what eventually lead to that talk. We don't really have the bandwidth to rewrite all the apps every quarter, especially since both shop and the data flow can be seen as guidelines in their own ways. Secondly, the two way binding in the shop elements mostly comes from the app-route element, which publishes its updates as properties, rather than events. As a result, if you want to use that element for routing, you need to use its two-way binding, whether you like it or not (and again, the element itself was written over 2 years ago, way before Gray's talk)

That being said, using two-way bindings is a personal preference: I personally dislike it, and don't use it in my projects (and that's the point of that talk as well: that if you want a simple, easier to debug app, you should avoid two-way binding). We've been doing a lot of explorations in the shop app recently, looking at Redux for state management, and using lit-html as a base, and in all of those we've steered away from two-way data binding.

That doesn't mean to say two-way binding is illegal: it's a feature of Polymer, and like every feature of every library, you should use it if it works for you.