Comments (5)
Discussion notes from Discord:
Previous decision to use v-slots
due to difficulty in determining the case where a dynamic expression is embedded:
const s = {
foo: () => <div>foo</div>,
bar: () => <div>bar</div>
}
<Comp>{s}</Comp>
Current output is
createVNode(resolveComponent("Comp"), null, {
default: () => [s],
_: 1
})
The solution is to add a runtime check:
const isSlot = s => isFunction(s) || (isObject(s) && !isVNode(s))
createVNode(resolveComponent("Comp"), null, isSlot(s) ? s : {
default: () => [s],
_: 1
})
The runtime check should only be needed in the case where:
- The JSX component has a single children expression
- The children expression is not a literal value (identifier, function call, other non-literal expressions)
Expected Cases
May not be complete.
-
JSX children: compile to default slot
<Comp><div>hi</div></Comp> createVNode(resolveComponent("Comp"), null, { default: () => [createVNode("div", null, [createTextVNode("hi")])], _: 1 })
-
Multiple expressions: compile to default slot
<Comp>{foo} {bar}</Comp> createVNode(resolveComponent("Comp"), null, { default: () => [foo, createTextVNode(" "), bar], _: 1 })
-
Single expression, non-literal value: runtime check
Note: may need to cache the expression in a variable to avoid multiple evaluations
<Comp>{foo()}</Comp> let _slot_1 createVNode(resolveComponent("Comp"), null, isSlot(_slot_1 = foo()) ? _slot_1 : { default: () => [_slot_1], _: 1 })
-
Single expression, object literal: pass as object slots
<Comp>{{ default: () => <div>default</div>, foo: () => <div>foo</div> }}</Comp> createVNode(resolveComponent("Comp"), null, { default: () => createVNode("div", null, [createTextVNode("default")]), foo: () => createVNode("div", null, [createTextVNode("foo")]), _: 1 })
-
Single expression, function expression: pass as default slot (no wrapping, no flag)
<Comp>{() => "foo"}</Comp> createVNode(resolveComponent("Comp"), null, { default: () => "foo" // probably should have no flag here })
-
Single expression, other literals: pass as default slot
<Comp>{123}</Comp> createVNode(resolveComponent("Comp"), null, { default: () => [normalizeVNode(123)], _: 1 })
from babel-plugin-jsx.
Is there any news about this new feature? ๐๐๐๐
WIP
from babel-plugin-jsx.
Would be nice to add children typing support if this is implemented.
from babel-plugin-jsx.
Finally, You found it.
The usage of v-slots
is quite react-like, may be provide more radical syntax sugar.
<Compo>
<VSlot name="default">
<div>default</div>
</VSlot>
<VSlot name="foo">
<div>bar</div>
</VSlot>
</Compo>
from babel-plugin-jsx.
Is there any news about this new feature? ๐๐๐๐
from babel-plugin-jsx.
Related Issues (20)
- [Question] In the future and Object slot typing be supported by this plugin HOT 2
- [Question] How to pass function slots ๏ผ HOT 1
- [BUG] empty string transform to true
- Action Required: Fix Renovate Configuration
- [BUG] empty string transform to true HOT 2
- [Question] How to pass any attribute to the component HOT 2
- [BUG] Excluding a file will prevent it from still getting parsed as JSX causing errors
- Can this plugin be used in a browser? HOT 1
- vModel ไฟฎ้ฅฐ็ฌฆไธ่ฝๅจๆ HOT 2
- [BUG] {} ๆธฒๆๅผๅธธ HOT 1
- [BUG] tsup bundle problem HOT 2
- [BUG] Typescript typings HOT 1
- [BUG] "resolveDirective" is imported from external module "vue" but never used
- [Question] Help้ ็ฝฎๅ่กจ HOT 1
- [Question] directives:v-model or vModel?v-show or vShow? HOT 1
- [BUG] Report bug HOT 1
- [Question] how to make vue jsx ast return to jsx HOT 1
- [Question] How to set a Symbolic Link in README.md HOT 2
- The inline style setting failed HOT 1
- When JSX is used, v-slots cause child component does unnecessary rendering during parent component re-rendering HOT 2
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 babel-plugin-jsx.