ganja.js icon indicating copy to clipboard operation
ganja.js copied to clipboard

interference with existing globally scoped `Element` and workaround

Open micahscopes opened this issue 2 years ago • 2 comments

I'm using vite to run some examples. Somehow the Element object is getting assigned to _Element in functions generated from the inline evaluator, so that the code in the generated functions references the existing window.Element used to make DOM elements.

I found a workaround that's working fine for me, which is to put const Element = this at the very beginning of the inline block.

micahscopes avatar Apr 08 '22 01:04 micahscopes

It would be nice to rename class Element extends generator in Ganja so it doesn't clash with HTML5 Element anymore, but what would be a better name?

kungfooman avatar May 22 '22 11:05 kungfooman

@kungfooman I'm nto sure if this covers what you're doing but I was able to work around my issues by just avoiding using this in the inline function body:

const cga = Algebra(4, 1);
const graphElements = cga.inline(() => {
  let p1 = // ... 
  // ...
  return [
    0x00ff0000, p1, "p1", p2, "p2", p3, "p3", p4, "p4", // points
    0xe0008800, p, "p", // plane
    0xe00000ff, s, "s", // sphere
  ];
})();

const graph = cga.graph(graphElements, {
  conformal: true,
  gl: true,
  grid: true,
  alpha: true,
});

graph.setAttribute("id", "graph");
document.body.appendChild(graph);

micahscopes avatar May 23 '22 22:05 micahscopes