simplajs / simpla-paths

Structure Simpla content in code with new HTML attributes
https://www.simplajs.org
MIT License
6 stars 0 forks source link

Use Symbols for path prop #2

Closed bedeoverend closed 7 years ago

bedeoverend commented 7 years ago

Right now we're just setting the path property on any element that has an sid / gid property. This is a risk if the user wants to use these attributes on elements that already have a path property that's used for something else. There's no standard HTML path property, but users could have a custom-element that adds it.

This could be resolved by using a Symbol, rather than a String as the property. This would protect for unknown elements.

From a simpla element's perspective, to keep the regular path property on them, as well as getting the value from simpla-paths, it would have to import the Symbol used by simpla-paths (not much weight given tree-shaking), and pass the value set by paths to it's own path property. e.g.

import { PathSymbol } from 'simpla-paths';

class SimplaText extends HTMLElement {
  set [ PathSymbol ](value) {
    this.path = value;
  }

  get [ PathSymbol ](value) {
    return this.path;
  }
}

A Symbol polyfill would also have to be bundled somewhere, as Symbols aren't supported at all by IE, AFAIK the polyfill is relatively lightweight e.g. are used by SkateJS.

madeleineostoja commented 7 years ago

I don't really see the benefit of this, considering the extra weight and inconvenience for element authors. I definitely don't think we should do this unless/until there is a strong need for it from users.

bedeoverend commented 7 years ago

Hmm...I might close this until we know definitely how much of a pain it is. It's definitely dodgy just setting properties on unknown elements, but I'm happy to wait until someone actually runs into the problem, it's a relatively small change anyway, so even though it's breaking, it wouldn't be much work to update other elements.