Netflix / x-element

A dead simple starting point for custom elements.
Apache License 2.0
28 stars 12 forks source link

Consider support for custom “updaters” in default template engine. #132

Open theengineear opened 1 year ago

theengineear commented 1 year ago

Just adding this for completeness. We likely have no need to expose custom updaters in our default templating engine, but if we ever wanted to, it could look something like this:

  static updater(update, transform) {
    return (value, ...args) => {
      const reference = Template.#createReference();
      const context = transform?.(...args);
      const updater = (type, lastValue, details) => {
        update(type, value, lastValue, details, context);
      };
      Template.#updaters.set(reference, { updater, value });
      return reference;
    };
  }

While it's not much of a code burden — it does pose an interface burden that might be hard to change in the future. IFF we really needed this, we could always add (harder to remove later than it is to add later).

Also note that other templating engines expose custom functionality like this — so it's possible to simply plug something else in if needed.