-
-
Notifications
You must be signed in to change notification settings - Fork 106
feat(runtime-vapor): component slot #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 41 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
d435acb
feat(runtime-vapor): component slot
ubugeeei 711645e
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei 61ada62
chore: render fn arg
ubugeeei f4768bc
chore playground
ubugeeei 0321374
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei ffee672
test(runtime-vapor): component slots (def test cases)
ubugeeei 246badc
test(runtime-vapor): component slots [wip]
ubugeeei 60edb08
chore: add comment
ubugeeei e3bfd50
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei d690331
chore: merge refactoring of component
ubugeeei e967ed1
chore: fix test
ubugeeei fd2d9ff
feat(runtime-vapor): dynamic slots
ubugeeei a5d9945
chore: fmt
ubugeeei 3e0d646
chore: slot playground
ubugeeei ab91662
chore: remove dead comments
ubugeeei 0159af9
chore: remove unnecessary diffs
ubugeeei 1e00d6c
chore: add comments
ubugeeei d83f04c
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei ac237ea
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei 5609644
chore: renderWatch -> renderEffect
ubugeeei 34ca9f5
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei 6a7957d
chore(runtime-vapor): remove slot arg of createVaporApp
ubugeeei d12c2ac
chore(runtime-vapor): provide slots to setup context
ubugeeei a259039
Merge remote-tracking branch 'origin/main' into ubugeeei/feat/compone…
sxzz 9c52df2
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei 463ae38
Merge branch 'ubugeeei/feat/component-slot' of github.com:vuejs/core-…
ubugeeei 9dfc966
refactor: tidy
sxzz 9c122eb
refactor(runtime-vapor): CompiledSlotDescriptor -> DynamicSlot
ubugeeei 9479dba
refactor(runtime-vapor): renderEffect -> baseWatch
ubugeeei a54617c
refactor(runtime-vapor): no export createSlots
ubugeeei 082f6a1
refactor(runtime-vapor): create component slots
ubugeeei 4d3a8e8
Merge branch 'ubugeeei/feat/component-slot' of github.com:vuejs/core-…
ubugeeei cf18747
chore(runtime-vapor): component slots tests
ubugeeei 38af9aa
feat(runtime-vapor): set dynamic slots updation scheduler
ubugeeei 13cc597
refactor(runtime-vapor): dynamic slots
ubugeeei f1f8b42
chore(runtime-vapor): remove dead test
ubugeeei 35feb3c
Merge branch 'main' of github.com:vuejs/core-vapor into ubugeeei/feat…
ubugeeei e04e00a
chore: remove tracking $slots
ubugeeei f6afe50
refactor: for -> extend
ubugeeei a8a7e47
chore: typo (DinamicSlots -> DynamicSlots)
ubugeeei 08cc2bc
chore: remove dead codes
ubugeeei c633534
chore(runtime-vapor): make slotsProxy optional
ubugeeei 5b76208
chore(runtime-vapor): make attrsProxy optional
ubugeeei 9510748
chore: update
sxzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
packages/runtime-vapor/__tests__/componentSlots.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
// NOTE: This test is implemented based on the case of `runtime-core/__test__/componentSlots.spec.ts`. | ||
|
||
import { | ||
createComponent, | ||
createVaporApp, | ||
defineComponent, | ||
getCurrentInstance, | ||
nextTick, | ||
ref, | ||
template, | ||
} from '../src' | ||
import { makeRender } from './_utils' | ||
|
||
const define = makeRender<any>() | ||
|
||
describe('component: slots', () => { | ||
function renderWithSlots(slots: any): any { | ||
let instance: any | ||
const Comp = defineComponent({ | ||
vapor: true, | ||
render() { | ||
const t0 = template('<div></div>') | ||
const n0 = t0() | ||
instance = getCurrentInstance() | ||
return n0 | ||
}, | ||
}) | ||
|
||
const { render } = define({ | ||
render() { | ||
return createComponent(Comp, {}, slots) | ||
}, | ||
}) | ||
|
||
render() | ||
return instance | ||
} | ||
|
||
test('initSlots: instance.slots should be set correctly', () => { | ||
const { slots } = renderWithSlots({ _: 1 }) | ||
expect(slots).toMatchObject({ _: 1 }) | ||
}) | ||
|
||
// NOTE: slot normalization is not supported | ||
// test.todo( | ||
// 'initSlots: should normalize object slots (when value is null, string, array)', | ||
// () => {}, | ||
// ) | ||
// test.todo( | ||
// 'initSlots: should normalize object slots (when value is function)', | ||
// () => {}, | ||
// ) | ||
|
||
test('initSlots: instance.slots should be set correctly', () => { | ||
let instance: any | ||
const Comp = defineComponent({ | ||
render() { | ||
const t0 = template('<div></div>') | ||
const n0 = t0() | ||
instance = getCurrentInstance() | ||
return n0 | ||
}, | ||
}) | ||
|
||
const { render } = define({ | ||
render() { | ||
return createComponent(Comp, {}, { header: () => template('header')() }) | ||
}, | ||
}) | ||
|
||
render() | ||
|
||
expect(instance.slots.header()).toMatchObject( | ||
document.createTextNode('header'), | ||
) | ||
}) | ||
|
||
// runtime-core's "initSlots: instance.slots should be set correctly (when vnode.shapeFlag is not SLOTS_CHILDREN)" | ||
test('initSlots: instance.slots should be set correctly', () => { | ||
const { slots } = renderWithSlots({ | ||
default: () => template('<span></span>')(), | ||
}) | ||
|
||
// expect( | ||
// '[Vue warn]: Non-function value encountered for default slot. Prefer function slots for better performance.', | ||
// ).toHaveBeenWarned() | ||
|
||
expect(slots.default()).toMatchObject(document.createElement('span')) | ||
}) | ||
|
||
test('updateSlots: instance.slots should be updated correctly', async () => { | ||
const flag1 = ref(true) | ||
|
||
let instance: any | ||
const Child = () => { | ||
instance = getCurrentInstance() | ||
return template('child')() | ||
} | ||
|
||
const { render } = define({ | ||
render() { | ||
return createComponent(Child, {}, { _: 2 as any }, () => [ | ||
flag1.value | ||
? { name: 'one', fn: () => template('<span></span>')() } | ||
: { name: 'two', fn: () => template('<div></div>')() }, | ||
]) | ||
}, | ||
}) | ||
|
||
render() | ||
|
||
expect(instance.slots).toHaveProperty('one') | ||
expect(instance.slots).not.toHaveProperty('two') | ||
|
||
flag1.value = false | ||
await nextTick() | ||
|
||
expect(instance.slots).not.toHaveProperty('one') | ||
expect(instance.slots).toHaveProperty('two') | ||
}) | ||
|
||
// NOTE: it is not supported | ||
// test('updateSlots: instance.slots should be updated correctly (when slotType is null)', () => {}) | ||
|
||
// runtime-core's "updateSlots: instance.slots should be update correctly (when vnode.shapeFlag is not SLOTS_CHILDREN)" | ||
test('updateSlots: instance.slots should be update correctly', async () => { | ||
const flag1 = ref(true) | ||
|
||
let instance: any | ||
const Child = () => { | ||
instance = getCurrentInstance() | ||
return template('child')() | ||
} | ||
|
||
const { render } = define({ | ||
setup() { | ||
return createComponent(Child, {}, {}, () => [ | ||
flag1.value | ||
? [{ name: 'header', fn: () => template('header')() }] | ||
: [{ name: 'footer', fn: () => template('footer')() }], | ||
]) | ||
}, | ||
}) | ||
render() | ||
|
||
expect(instance.slots).toHaveProperty('header') | ||
flag1.value = false | ||
await nextTick() | ||
|
||
// expect( | ||
// '[Vue warn]: Non-function value encountered for default slot. Prefer function slots for better performance.', | ||
// ).toHaveBeenWarned() | ||
|
||
expect(instance.slots).toHaveProperty('footer') | ||
}) | ||
|
||
test.todo('should respect $stable flag', async () => { | ||
// TODO: $stable flag? | ||
}) | ||
|
||
test.todo('should not warn when mounting another app in setup', () => { | ||
// TODO: warning | ||
const Comp = defineComponent({ | ||
render() { | ||
const i = getCurrentInstance() | ||
return i!.slots.default!() | ||
}, | ||
}) | ||
const mountComp = () => { | ||
createVaporApp({ | ||
render() { | ||
return createComponent( | ||
Comp, | ||
{}, | ||
{ default: () => template('msg')() }, | ||
)! | ||
}, | ||
}) | ||
} | ||
const App = { | ||
setup() { | ||
mountComp() | ||
}, | ||
render() { | ||
return null! | ||
}, | ||
} | ||
createVaporApp(App).mount(document.createElement('div')) | ||
expect( | ||
'Slot "default" invoked outside of the render function', | ||
).not.toHaveBeenWarned() | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.