Giter Club home page Giter Club logo

Comments (5)

ryansolid avatar ryansolid commented on August 20, 2024 1

I actually can change this. I was worried about this case:

function MyComp(prop) {
  return <div ref={props.ref} />
}

<MyComp />

If props.ref isn't passed in I can't tell if the intention is to assign it or simply it's missing. But I realized since props are readonly, even if it gets assigned who cares. It just doesn't update. Right now that scenario is compiled to:

props.ref && props.ref(el)

I can change it to:

typeof props.ref === "function" ? props.ref($el) : props.ref = $el;

While it is meaningless in this case if isn't passed in. This will also work for a simple ref:

typeof el1 === "function" ? el1($el) : el1 = $el;

Overall it's more code but it only runs once on creation and I don't think it makes that much of a difference on size.

from dom-expressions.

ryansolid avatar ryansolid commented on August 20, 2024

Sorry I need a bit more context. Generally speaking you need to configure a dom-expressions runtime to work with. Which requires building it with the library of choice.

So first question is are you attempting to use this plugin with one of my libraries... like Solid, MobX-JSX, or Knockout-JSX? Or are you trying your own reactive library?

Next question, what does index.js look like? It's hard to see what this is in the dark without an idea of what you are trying to compile.

The documentation here is light mostly in that it is the specific libraries documentation that I usually rely on. I haven't streamlined the process as much as I like for people trying to write their own reactive libraries on top. So I do apologize for the lack of documentation if that is what you are after.

from dom-expressions.

elclanrs avatar elclanrs commented on August 20, 2024

Actually, I figured out why it doesn't compile. The error is because of my use of ref here:

export default <>
  <div ref={div => {
    console.log(div);
  }}></div>
</>;

The above compiles fine with transform-syntax-jsx.

Is this error expected?

from dom-expressions.

ryansolid avatar ryansolid commented on August 20, 2024

Yes.. my refs are a bit different. Although I am reviewing it. I have two types and I haven't figure out how to merge them from a compiler/runtime perspective.

There are refs which assign ref:

let myVar;
<>
  <div ref={myVar}></div>
</>;

And ones that call functions forwardRef:

<>
  <div forwardRef={div => {
    console.log(div);
  }}></div>
</>;

I'm not sure how useful the first case is but the simple assignment option seems nice and sort of parallels react's createRef other than it's just plain JavaScript.

https://github.com/ryansolid/dom-expressions/tree/master/packages/babel-plugin-jsx-dom-expressions#special-binding

Also in Solid:
https://github.com/ryansolid/solid/blob/master/documentation/rendering.md#refs

from dom-expressions.

elclanrs avatar elclanrs commented on August 20, 2024

Thank you, I must've missed that part in the docs and just made the assumption. It'd be ideal if it takes both vars and callbacks, but I understand that may be a limitation currently.

from dom-expressions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.