Skip to content
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

Add Task args as argument to Task callbacks #4605

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Snapstromegon
Copy link
Contributor

Fixes #4561

This adds the args from the args function as an argument to the callbacks like mentioned here: #4561 (comment)

This is my first contribution to the projects, so I tried following CONTRIBUTING.md, but developing on Windows is hard in this project, since executing tests is not possible (other scripts only work in WSL and not natively in windows - at least for me).

Copy link

changeset-bot bot commented Mar 30, 2024

🦋 Changeset detected

Latest commit: ecf8080

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit/task Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

📊 Tachometer Benchmark Results

Summary

A summary of the benchmark results will show here once they finish.

Results

The full results of your benchmarks will show here once they finish.

tachometer-reporter-action v2 for Benchmarks

Copy link
Collaborator

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small required fix to keep this a backwards compatible change.

pending?: () => unknown;
complete?: (value: R) => unknown;
error?: (error: unknown) => unknown;
export type StatusRenderer<R, D extends ReadonlyArray<unknown>> = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backwards compatibility: in case someone is using this type directly in an annotation, I think we need a default value for D so it can be omitted:

Suggested change
export type StatusRenderer<R, D extends ReadonlyArray<unknown>> = {
export type StatusRenderer<R, D extends ReadonlyArray<unknown> = ReadonlyArray<unknown>> = {

pending?: () => unknown;
complete?: (value: R) => unknown;
error?: (error: unknown) => unknown;
export type StatusRenderer<R, D extends ReadonlyArray<unknown>> = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call the args type T elsewhere, so I'd either stick with that or give all the type parameters better names like Result and Args.

switch (this.status) {
case TaskStatus.INITIAL:
return renderer.initial?.() as MaybeReturnType<T['initial']>;
return renderer.initial?.(this._previousArgs) as MaybeReturnType<
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_previousArgs doesn't sound quite right anymore if we're using them for the current render. Maybe it should be named _latestArgs?

@justinfagnani
Copy link
Collaborator

Thanks @Snapstromegon!

…Args and adapt generic types.

Signed-off-by: Raphael Höser <raphael@hoeser.info>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[task] Passing the parameters inside the task render callback
2 participants