Why do Polymer's computed properties need explicit property arguments? -
i digging bit polymer 1.0 elements , little curious computed properties.
for example, in paper-drawer-panel.html,
<dom-module id="paper-drawer-panel" …> … <div id="main" style$="[[_computedrawerstyle(drawerwidth)]]"> … </div> … </dom-module> <script> polymer({ is: 'paper-drawer-panel', … _computedrawerstyle: function(drawerwidth) { return 'width:' + drawerwidth + ';'; }, … </script>
drawerwidth
property of paper-drawer-panel
, why important explicitly include in parameters of computed property?
is
[[_computedrawerstyle()]] … _computedrawerstyle: function () { return 'width:' + this.drawerwidth + ';'; }
is bad practice?
explicit arguments in computed bindings serve important purpose: telling polymer properties computed binding depends on. allows polymer know when recalculate , update computed binding.
take [[_computedrawerstyle()]]
, example. in case, polymer has no idea other properties computed binding depends on, , calculate once on load.
as add drawerwidth
explicitly ([[_computedrawerstyle(drawerwidth)]]
) polymer knows should run computed binding again new value every time drawerwidth
changes.
Comments
Post a Comment