@lit-labs/task
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -19,3 +19,3 @@ import { ReactiveControllerHost } from '@lit/reactive-element/reactive-controller.js'; | ||
export declare const initialState: unique symbol; | ||
export declare type TaskStatus = typeof TaskStatus[keyof typeof TaskStatus]; | ||
export declare type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus]; | ||
export declare type StatusRenderer<R> = { | ||
@@ -22,0 +22,0 @@ initial?: () => unknown; |
@@ -136,4 +136,5 @@ /** | ||
let error; | ||
// Request an update to report pending state. | ||
this._host.requestUpdate(); | ||
// Request an update to report pending state. Do this in a | ||
// microtask to avoid the change-in-update warning | ||
queueMicrotask(() => this._host.requestUpdate()); | ||
const key = ++this._callId; | ||
@@ -140,0 +141,0 @@ try { |
{ | ||
"name": "@lit-labs/task", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A controller for Lit that renders asynchronous tasks.", | ||
@@ -121,2 +121,7 @@ "license": "BSD-3-Clause", | ||
], | ||
"env": { | ||
"BROWSERS": { | ||
"external": true | ||
} | ||
}, | ||
"files": [], | ||
@@ -131,2 +136,7 @@ "output": [] | ||
], | ||
"env": { | ||
"BROWSERS": { | ||
"external": true | ||
} | ||
}, | ||
"files": [], | ||
@@ -133,0 +143,0 @@ "output": [] |
@@ -52,3 +52,3 @@ # @lit-labs/task | ||
@state() | ||
private _userId: number; | ||
private _userId: number = -1; | ||
@@ -61,3 +61,3 @@ private _apiTask = new Task( | ||
), | ||
() => [this.userId] | ||
() => [this._userId] | ||
); | ||
@@ -64,0 +64,0 @@ |
@@ -19,3 +19,3 @@ import { ReactiveControllerHost } from '@lit/reactive-element/reactive-controller.js'; | ||
export declare const initialState: unique symbol; | ||
export declare type TaskStatus = typeof TaskStatus[keyof typeof TaskStatus]; | ||
export declare type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus]; | ||
export declare type StatusRenderer<R> = { | ||
@@ -22,0 +22,0 @@ initial?: () => unknown; |
@@ -6,3 +6,3 @@ import{notEqual as t}from"@lit/reactive-element"; | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/const i={INITIAL:0,PENDING:1,COMPLETE:2,ERROR:3},s=Symbol();class h{constructor(t,i,s){this.i=0,this.status=0,this.autoRun=!0,this.o=t,this.o.addController(this);const h="object"==typeof i?i:{task:i,args:s};this.t=h.task,this.h=h.args,this.l=h.onComplete,this.u=h.onError,void 0!==h.autoRun&&(this.autoRun=h.autoRun),this.taskComplete=new Promise(((t,i)=>{this.v=t,this._=i}))}hostUpdated(){this.performTask()}async performTask(){var t;const i=null===(t=this.h)||void 0===t?void 0:t.call(this);this.shouldRun(i)&&this.run(i)}shouldRun(t){return this.autoRun&&this.m(t)}async run(t){var i,h,r;let e,o;null!=t||(t=null===(i=this.h)||void 0===i?void 0:i.call(this)),2!==this.status&&3!==this.status||(this.taskComplete=new Promise(((t,i)=>{this.v=t,this._=i}))),this.status=1,this.o.requestUpdate();const n=++this.i;try{e=await this.t(t)}catch(t){o=t}if(this.i===n){if(e===s)this.status=0;else{if(void 0===o){try{null===(h=this.l)||void 0===h||h.call(this,e)}catch{}this.status=2,this.v(e)}else{try{null===(r=this.u)||void 0===r||r.call(this,o)}catch{}this.status=3,this._(o)}this.T=e,this.k=o}this.o.requestUpdate()}}get value(){return this.T}get error(){return this.k}render(t){var i,s,h,r;switch(this.status){case 0:return null===(i=t.initial)||void 0===i?void 0:i.call(t);case 1:return null===(s=t.pending)||void 0===s?void 0:s.call(t);case 2:return null===(h=t.complete)||void 0===h?void 0:h.call(t,this.value);case 3:return null===(r=t.error)||void 0===r?void 0:r.call(t,this.error);default:this.status}}m(i){const s=this.p;return this.p=i,Array.isArray(i)&&Array.isArray(s)?i.length===s.length&&i.some(((i,h)=>t(i,s[h]))):i!==s}}export{h as Task,i as TaskStatus,s as initialState}; | ||
*/const i={INITIAL:0,PENDING:1,COMPLETE:2,ERROR:3},s=Symbol();class h{constructor(t,i,s){this.i=0,this.status=0,this.autoRun=!0,this.o=t,this.o.addController(this);const h="object"==typeof i?i:{task:i,args:s};this.t=h.task,this.h=h.args,this.l=h.onComplete,this.u=h.onError,void 0!==h.autoRun&&(this.autoRun=h.autoRun),this.taskComplete=new Promise(((t,i)=>{this.v=t,this._=i}))}hostUpdated(){this.performTask()}async performTask(){var t;const i=null===(t=this.h)||void 0===t?void 0:t.call(this);this.shouldRun(i)&&this.run(i)}shouldRun(t){return this.autoRun&&this.k(t)}async run(t){var i,h,r;let e,o;null!=t||(t=null===(i=this.h)||void 0===i?void 0:i.call(this)),2!==this.status&&3!==this.status||(this.taskComplete=new Promise(((t,i)=>{this.v=t,this._=i}))),this.status=1,queueMicrotask((()=>this.o.requestUpdate()));const n=++this.i;try{e=await this.t(t)}catch(t){o=t}if(this.i===n){if(e===s)this.status=0;else{if(void 0===o){try{null===(h=this.l)||void 0===h||h.call(this,e)}catch{}this.status=2,this.v(e)}else{try{null===(r=this.u)||void 0===r||r.call(this,o)}catch{}this.status=3,this._(o)}this.m=e,this.T=o}this.o.requestUpdate()}}get value(){return this.m}get error(){return this.T}render(t){var i,s,h,r;switch(this.status){case 0:return null===(i=t.initial)||void 0===i?void 0:i.call(t);case 1:return null===(s=t.pending)||void 0===s?void 0:s.call(t);case 2:return null===(h=t.complete)||void 0===h?void 0:h.call(t,this.value);case 3:return null===(r=t.error)||void 0===r?void 0:r.call(t,this.error);default:this.status}}k(i){const s=this.p;return this.p=i,Array.isArray(i)&&Array.isArray(s)?i.length===s.length&&i.some(((i,h)=>t(i,s[h]))):i!==s}}export{h as Task,i as TaskStatus,s as initialState}; | ||
//# sourceMappingURL=task.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
57716
477