ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
858 stars 125 forks source link

Can't use `this` on prop function #247

Closed titoBouzout closed 9 months ago

titoBouzout commented 1 year ago

I was trying to use this on a function given to props. It gets changed to _self$. Possibly this has to do with component classes from mobx-jsx?

function Component() {
  return (
    <div
      prop:update={function () {
        console.log(this);
      }.bind({ one: true })}
    />
  );
}

compiles to:

function Component() {
  const _self$ = this;
  return (() => {
    const _el$ = _tmpl$();
    _$effect(() => _el$.update = function () {
      console.log(_self$);
    }.bind({
      one: true
    }));
    return _el$;
  })();
}

Playground: https://playground.solidjs.com/anonymous/393c3426-bea9-4d4c-8af9-5cc28d451a47

titoBouzout commented 9 months ago

fixed in https://github.com/ryansolid/dom-expressions/commit/5b7b53d2ecb1c4fea679fbae6d165451fb5c3393