You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
It would be super useful to get the parameters inside the task render callback, for example to adjust the render output using these params.
For example:
import{Task,TaskStatus}from'@lit/task';// ...classMyElementextendsLitElement{
@state()private_userId: number=-1;private_apiTask=newTask(this,([userId])=>fetch(`//example.com/api/userInfo?${userId}`).then((response) =>response.json()),()=>[this._userId]);render(){returnhtml`<div>User Info</div>${this._apiTask.render({pending: ([userId])=>html`Loading user info by id:${userId}...`,error: ([userId])=>html`Loading user by id:${userId} failed :(`,complete: (user)=>html`${user.name}`,})}<!-- ... --> `;}}
Is this a regression?
No.
Affected versions
all
Browser/OS/Node environment
all
Alternatives and Workarounds
It's possible to achieve the same result by setting taskParams manualy in the LitElement instance. But I would like to avoid unecessary code
For example:
import{Task,TaskStatus}from"@lit/task";// ...classMyElementextendsLitElement{private_apiParams: [string]=[""];private_apiTask=newTask(this,{task: async([userId])=>{this._apiParams=[userId];constresponse=awaitfetch(`//example.com/api/userInfo?${userId}`);constjson=awaitresponse.json();returnjson;},autoRun: false,});/* I can now call this._apiTask.run() with different params */render(){returnhtml`<div>User Info</div>${this._apiTask.render({pending: ([userId])=>html`Loading user info by id:${this._apiParams[0]}...`,error: ([userId])=>html`Loading user by id:${this._apiParams[0]} failed :(`,complete: (user)=>html`${user.name}`,})}<!-- ... --> `;}}
The text was updated successfully, but these errors were encountered:
PRs very welcome for this. Just make sure that the error callback is backwards compatible and that the complete call is forwards compatible with new complete-specific arguments by passing the task args as an array there too.
Should this be an RFC?
Which package is this a feature request for?
Task (@lit/task)
Description
Which package(s) are affected?
Task (@lit/task)
Description
It would be super useful to get the parameters inside the task render callback, for example to adjust the render output using these params.
For example:
Is this a regression?
No.
Affected versions
all
Browser/OS/Node environment
all
Alternatives and Workarounds
It's possible to achieve the same result by setting taskParams manualy in the LitElement instance. But I would like to avoid unecessary code
For example:
The text was updated successfully, but these errors were encountered: