PolymerElements / iron-meta

Element for creating and accessing self-organizing meta-databases
25 stars 20 forks source link

Guidance for updating to the 2.0 version #50

Open rictic opened 7 years ago

rictic commented 7 years ago

I'm taking a look at updating some usages of this element to the 2.0 version inside google and here are my notes so far:

Once I've got this worked out I'll send over a PR to update the README with some upgrade guidance.

rictic commented 7 years ago

Hm, changing <iron-meta-query key="foo" value="{{bar}}"> to <iron-meta key="foo" value="{{bar}}"> isn't quite right, because if bar changes, with iron-meta-query it would not be pushed down into the store. What we really want is to read the property from the iron-meta but never to write it.

I guess the best way to emulate this would be to create a new property _barReadOnly on the parent, then in its observer do this.bar = this._barReadOnly.

rictic commented 7 years ago

My first gambit of just changing all <iron-meta-query> instances to <iron-meta> did break a handful of things. Mostly in one app.

notwaldorf commented 7 years ago

/cc @cdata

rictic commented 6 years ago

/cc @bicknellr

bicknellr commented 6 years ago

Generally, I've found that most updates to hybrid end up looking like this:

before:

<dom-module id="some-element">
  <template>
    <iron-meta-query key="K" value="{{valueToExtract}}"></iron-meta>
    Then, use the [[valueToExtract]] somewhere else in the template.
  </template>
  <script>
    Polymer({
      is: 'some-element',
    });
  </script>
</dom-module>

after:

<dom-module id="some-element">
  <template>
    Then, use the [[valueToExtract]] somewhere else in the template.
  </template>
  <script>
    (function() {
      const ironMeta = new Polymer.IronMeta(/* required! */ {});
      Polymer({
        is: 'some-element',

        properties: {
          valueToExtract: {
            value: function() {
              // Use the imperative interface to get values.
              return ironMeta.byKey("K");
            }
          }
        }
      });
    })();
  </script>
</dom-module>

(1.x...master diff link for reference.)