-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) handle multiple event dispatchers (#938)
Merge definitions of multiple `createEventDispatcher`-instantations as well as bubbled events. #921
- Loading branch information
1 parent
d73447d
commit 562c944
Showing
11 changed files
with
195 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
9 changes: 9 additions & 0 deletions
9
packages/svelte2tsx/test/svelte2tsx/samples/event-dispatchers/expected.js
This file contains 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,9 @@ | ||
let assert = require('assert'); | ||
|
||
module.exports = function ({ events }) { | ||
assert.deepEqual(events.getAll(), [ | ||
{ name: 'click', type: 'Event' }, | ||
{ name: 'hi', type: 'CustomEvent<any>' }, | ||
{ name: 'bye', type: 'CustomEvent<any>' } | ||
]); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/svelte2tsx/test/svelte2tsx/samples/event-dispatchers/expected.tsx
This file contains 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,21 @@ | ||
///<reference types="svelte" /> | ||
<></>; | ||
import { createEventDispatcher, abc } from "svelte"; | ||
function render() { | ||
|
||
|
||
|
||
const notDispatch = abc(); | ||
const dispatch1 = createEventDispatcher(); | ||
const dispatch2 = createEventDispatcher(); | ||
|
||
dispatch1('hi', true); | ||
dispatch2('bye', true); | ||
; | ||
() => (<> | ||
|
||
<button onclick={undefined}></button></>); | ||
return { props: {}, slots: {}, getters: {}, events: {'click':__sveltets_mapElementEvent('click'), 'hi': __sveltets_customEvent, 'bye': __sveltets_customEvent} }} | ||
|
||
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/svelte2tsx/test/svelte2tsx/samples/event-dispatchers/input.svelte
This file contains 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,12 @@ | ||
<script> | ||
import { createEventDispatcher, abc } from "svelte"; | ||
const notDispatch = abc(); | ||
const dispatch1 = createEventDispatcher(); | ||
const dispatch2 = createEventDispatcher(); | ||
dispatch1('hi', true); | ||
dispatch2('bye', true); | ||
</script> | ||
|
||
<button on:click></button> |
This file contains 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
9 changes: 9 additions & 0 deletions
9
packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatchers-same-event/expected.js
This file contains 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,9 @@ | ||
let assert = require('assert'); | ||
|
||
module.exports = function ({ events }) { | ||
assert.deepEqual(events.getAll(), [ | ||
{ name: 'click', type: 'Event' }, | ||
{ name: 'hi', type: 'CustomEvent<any>' }, | ||
{ name: 'bye', type: 'CustomEvent<any>' } | ||
]); | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatchers-same-event/expected.tsx
This file contains 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,31 @@ | ||
///<reference types="svelte" /> | ||
<></>; | ||
import { createEventDispatcher, abc } from "svelte"; | ||
function render() { | ||
|
||
|
||
|
||
const notDispatch = abc(); | ||
const dispatch1 = createEventDispatcher<{ | ||
/** | ||
* A DOC | ||
*/ | ||
hi: boolean; | ||
}>(); | ||
const dispatch2 = createEventDispatcher<{hi: string;}>(); | ||
const dispatch3 = createEventDispatcher(); | ||
|
||
dispatch3('bye', true); | ||
; | ||
() => (<> | ||
|
||
<button onclick={undefined}></button></>); | ||
return { props: {}, slots: {}, getters: {}, events: {...__sveltets_toEventTypings<{ | ||
/** | ||
* A DOC | ||
*/ | ||
hi: boolean; | ||
}>(), ...__sveltets_toEventTypings<{hi: string;}>(), 'click':__sveltets_mapElementEvent('click'), 'hi': __sveltets_customEvent, 'bye': __sveltets_customEvent} }} | ||
|
||
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial_ts(__sveltets_with_any_event(render))) { | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatchers-same-event/input.svelte
This file contains 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,17 @@ | ||
<script> | ||
import { createEventDispatcher, abc } from "svelte"; | ||
const notDispatch = abc(); | ||
const dispatch1 = createEventDispatcher<{ | ||
/** | ||
* A DOC | ||
*/ | ||
hi: boolean; | ||
}>(); | ||
const dispatch2 = createEventDispatcher<{hi: string;}>(); | ||
const dispatch3 = createEventDispatcher(); | ||
dispatch3('bye', true); | ||
</script> | ||
|
||
<button on:click></button> |
10 changes: 10 additions & 0 deletions
10
packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatchers/expected.js
This file contains 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,10 @@ | ||
let assert = require('assert'); | ||
|
||
module.exports = function ({ events }) { | ||
assert.deepEqual(events.getAll(), [ | ||
{ name: 'click', type: 'Event' }, | ||
{ name: 'hi', type: 'CustomEvent<boolean>', doc: '\nA DOC\n' }, | ||
{ name: 'btn', type: 'CustomEvent<string>', doc: undefined }, | ||
{ name: 'bye', type: 'CustomEvent<any>' } | ||
]); | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatchers/expected.tsx
This file contains 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,31 @@ | ||
///<reference types="svelte" /> | ||
<></>; | ||
import { createEventDispatcher, abc } from "svelte"; | ||
function render() { | ||
|
||
|
||
|
||
const notDispatch = abc(); | ||
const dispatch1 = createEventDispatcher<{ | ||
/** | ||
* A DOC | ||
*/ | ||
hi: boolean; | ||
}>(); | ||
const dispatch2 = createEventDispatcher<{btn: string;}>(); | ||
const dispatch3 = createEventDispatcher(); | ||
|
||
dispatch3('bye', true); | ||
; | ||
() => (<> | ||
|
||
<button onclick={undefined}></button></>); | ||
return { props: {}, slots: {}, getters: {}, events: {...__sveltets_toEventTypings<{ | ||
/** | ||
* A DOC | ||
*/ | ||
hi: boolean; | ||
}>(), ...__sveltets_toEventTypings<{btn: string;}>(), 'click':__sveltets_mapElementEvent('click'), 'bye': __sveltets_customEvent} }} | ||
|
||
export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial_ts(__sveltets_with_any_event(render))) { | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatchers/input.svelte
This file contains 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,17 @@ | ||
<script> | ||
import { createEventDispatcher, abc } from "svelte"; | ||
const notDispatch = abc(); | ||
const dispatch1 = createEventDispatcher<{ | ||
/** | ||
* A DOC | ||
*/ | ||
hi: boolean; | ||
}>(); | ||
const dispatch2 = createEventDispatcher<{btn: string;}>(); | ||
const dispatch3 = createEventDispatcher(); | ||
dispatch3('bye', true); | ||
</script> | ||
|
||
<button on:click></button> |