ractivejs/ractive

Ambiguity warning adding observer from a decorator's teardown function

Closed this issue · 0 comments

Description:

Minor issue, but might be worth taking a look.
See my comments in the code.

Versions affected:

1.3.13, edge

Platforms affected:

All

Reproduction:

JSFiddle

Ractive.defaults.warnAboutAmbiguity = true;

const MyComponent = Ractive.extend({
  template: `
  <div as-decorated>My decorator</div>
  `,

  warnAboutAmbiguity: true,

  decorators: {
    decorated(node) {
      return {
        teardown: () => {
          // getting `myData` doesn't throw an ambiguity warning
          console.log(this.get('myData'));

          // throws an ambiguity warning
          this.observeOnce('myData', () => {});
        },
      };
    },
  },

  data() {
    return {
      myData: [],
    };
  },
});

Ractive.components.MyComponent = MyComponent;

const r = window.r = new Ractive({
  el: '#main',
  template: `
    {{#if showComponent}}
      <MyComponent></MyComponent>
    {{/if}}
  `,

  data() {
    return {
      showComponent: true,
    };
  },

  oncomplete() {
    this.toggle('showComponent');
  },
});