Comments (5)
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.
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.
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.
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.
Also in Solid:
https://github.com/ryansolid/solid/blob/master/documentation/rendering.md#refs
from dom-expressions.
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)
- [html] top level <style> causes TypeError: Cannot read properties of undefined (reading 'firstChild')
- [html] empty html template causes TypeError: Cannot read properties of undefined (reading 'name')
- `o[1] is not a function`
- There is no definition of `media` property in interface `MetaHTMLAttributes`
- Bug in generic types for universal render target? HOT 5
- Type definitions of `classList` are wrong HOT 8
- Treat `inert` as a boolean attribute
- Support combining tag classes and the class property in hyper dom expressions HOT 1
- Don't consider namespace imports to be dynamic expression HOT 3
- Emit var instead of const for generated element references HOT 7
- Add ability not to treat every tag with `-` in name as web component HOT 4
- `this` inside arrow function is incorrect after Solid transform HOT 3
- `<this.Foo />` doesn't work HOT 2
- Supporting iterable collections HOT 4
- Question: Possible to use third-party component libraries with Tagged Template Literals? HOT 6
- Template generation template literal escape problem
- bug: Compilation from JSX style attribute to ternary results in functions getting called twice HOT 1
- JSX attribute types HOT 2
- Option for preserving whitespace within JSXChildren HOT 1
- Fragment loses reactivity when using HDE HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dom-expressions.