-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: attachments fromAction
utility
#15933
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 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3672e29
feat: attachments `fromAction` utility
paoloricciuti 5a18de2
fix: typing of the utility
paoloricciuti 7d6fea7
simplify implementation - create action first, then only create updat…
Rich-Harris a4981b9
add since
Rich-Harris 42662e4
regenerate
Rich-Harris 585d81c
remove FromAction interface
Rich-Harris 35a3b47
Merge branch 'main' into from-action
Rich-Harris d166cd6
Merge branch 'from-action' into from-action-remove-interface
Rich-Harris 7c2a49e
overload
Rich-Harris d190509
fix: use typedef instead of exported interface
paoloricciuti 1d4aa8a
Merge remote-tracking branch 'origin/from-action-remove-interface' in…
paoloricciuti 11e086b
get rid of the arg0, arg1 stuff
Rich-Harris c7bd175
oops
Rich-Harris 09da021
god i hate overloads
Rich-Harris 5a963d1
defer to the reference documentation
Rich-Harris 7e1e277
damn ur weird typescript
Rich-Harris e12c331
gah
Rich-Harris 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': minor | ||
--- | ||
|
||
feat: attachments `fromAction` utility |
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
116 changes: 116 additions & 0 deletions
116
packages/svelte/tests/runtime-runes/samples/attachment-from-action/_config.js
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,116 @@ | ||
import { ok, test } from '../../test'; | ||
import { flushSync } from 'svelte'; | ||
|
||
export default test({ | ||
async test({ assert, target, logs }) { | ||
const [btn, btn2, btn3] = target.querySelectorAll('button'); | ||
|
||
// both logs on creation it will not log on change | ||
assert.deepEqual(logs, ['create', 0, 'action', 'create', 0, 'attachment']); | ||
|
||
// clicking the first button logs the right value | ||
flushSync(() => { | ||
btn?.click(); | ||
}); | ||
assert.deepEqual(logs, ['create', 0, 'action', 'create', 0, 'attachment', 0]); | ||
|
||
// clicking the second button logs the right value | ||
flushSync(() => { | ||
btn2?.click(); | ||
}); | ||
assert.deepEqual(logs, ['create', 0, 'action', 'create', 0, 'attachment', 0, 0]); | ||
|
||
// updating the arguments logs the update function for both | ||
flushSync(() => { | ||
btn3?.click(); | ||
}); | ||
assert.deepEqual(logs, [ | ||
'create', | ||
0, | ||
'action', | ||
'create', | ||
0, | ||
'attachment', | ||
0, | ||
0, | ||
'update', | ||
1, | ||
'action', | ||
'update', | ||
1, | ||
'attachment' | ||
]); | ||
|
||
// clicking the first button again shows the right value | ||
flushSync(() => { | ||
btn?.click(); | ||
}); | ||
assert.deepEqual(logs, [ | ||
'create', | ||
0, | ||
'action', | ||
'create', | ||
0, | ||
'attachment', | ||
0, | ||
0, | ||
'update', | ||
1, | ||
'action', | ||
'update', | ||
1, | ||
'attachment', | ||
1 | ||
]); | ||
|
||
// clicking the second button again shows the right value | ||
flushSync(() => { | ||
btn2?.click(); | ||
}); | ||
assert.deepEqual(logs, [ | ||
'create', | ||
0, | ||
'action', | ||
'create', | ||
0, | ||
'attachment', | ||
0, | ||
0, | ||
'update', | ||
1, | ||
'action', | ||
'update', | ||
1, | ||
'attachment', | ||
1, | ||
1 | ||
]); | ||
|
||
// unmounting logs the destroy function for both | ||
flushSync(() => { | ||
btn3?.click(); | ||
}); | ||
assert.deepEqual(logs, [ | ||
'create', | ||
0, | ||
'action', | ||
'create', | ||
0, | ||
'attachment', | ||
0, | ||
0, | ||
'update', | ||
1, | ||
'action', | ||
'update', | ||
1, | ||
'attachment', | ||
1, | ||
1, | ||
'destroy', | ||
'action', | ||
'destroy', | ||
'attachment' | ||
]); | ||
} | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/svelte/tests/runtime-runes/samples/attachment-from-action/main.svelte
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,37 @@ | ||
<script> | ||
import { fromAction } from 'svelte/attachments'; | ||
let { count = 0 } = $props(); | ||
|
||
function test(node, thing) { | ||
const kind = node.dataset.kind; | ||
console.log('create', thing, kind); | ||
let t = thing; | ||
const controller = new AbortController(); | ||
node.addEventListener( | ||
'click', | ||
() => { | ||
console.log(t); | ||
}, | ||
{ | ||
signal: controller.signal | ||
} | ||
); | ||
return { | ||
update(new_thing) { | ||
console.log('update', new_thing, kind); | ||
t = new_thing; | ||
}, | ||
destroy() { | ||
console.log('destroy', kind); | ||
controller.abort(); | ||
} | ||
}; | ||
} | ||
</script> | ||
|
||
{#if count < 2} | ||
<button data-kind="action" use:test={count}></button> | ||
<button data-kind="attachment" {@attach fromAction(test, ()=>count)}></button> | ||
{/if} | ||
|
||
<button onclick={()=> count++}></button> |
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
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.