fix(core): update
This commit is contained in:
		| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@design.estate/dees-element', | ||||
|   version: '2.0.25', | ||||
|   version: '2.0.26', | ||||
|   description: 'a custom element class extending lit element class' | ||||
| } | ||||
|   | ||||
| @@ -1,36 +1,46 @@ | ||||
| import { noChange } from 'lit'; | ||||
| import { AsyncDirective, directive } from 'lit/async-directive.js'; | ||||
| import { rxjs } from '@push.rocks/smartrx'; | ||||
|  | ||||
| class ResolveDirective extends AsyncDirective { | ||||
|   observable: rxjs.Observable<unknown> | undefined; | ||||
|   sub: rxjs.Subscription | null = null; | ||||
|   promise: Promise<unknown> | undefined; | ||||
|   hasPromiseSettled: boolean = false; | ||||
|  | ||||
|   render(observable: rxjs.Observable<unknown>) { | ||||
|     if (this.observable !== observable) { | ||||
|       this.sub?.unsubscribe(); | ||||
|       this.observable = observable; | ||||
|   render(promise: Promise<unknown>) { | ||||
|     if (this.promise !== promise) { | ||||
|       this.promise = promise; | ||||
|  | ||||
|       if (this.isConnected) { | ||||
|         this.subscribe(observable); | ||||
|         this.handlePromise(promise); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return noChange; | ||||
|   } | ||||
|  | ||||
|   subscribe(observable: rxjs.Observable<unknown>) { | ||||
|     this.sub = observable.subscribe((v: unknown) => { | ||||
|       this.setValue(v); | ||||
|   handlePromise(promise: Promise<unknown>) { | ||||
|     this.hasPromiseSettled = false; | ||||
|  | ||||
|     promise.then((value) => { | ||||
|       if (this.promise === promise && !this.hasPromiseSettled) { | ||||
|         this.setValue(value); | ||||
|         this.hasPromiseSettled = true; | ||||
|       } | ||||
|     }).catch((error) => { | ||||
|       if (this.promise === promise && !this.hasPromiseSettled) { | ||||
|         this.setValue(error); | ||||
|         this.hasPromiseSettled = true; | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   disconnected() { | ||||
|     this.sub?.unsubscribe(); | ||||
|     this.hasPromiseSettled = true; // prevent setting value if the promise settles after disconnection | ||||
|   } | ||||
|  | ||||
|   reconnected() { | ||||
|     this.subscribe(this.observable!); | ||||
|     if (!this.hasPromiseSettled) { | ||||
|       this.handlePromise(this.promise!); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -24,3 +24,12 @@ export * from './dees-element.classes.resolvedirective.js'; | ||||
|  * a singleton instance of CssManager | ||||
|  */ | ||||
| export const cssManager = new CssManager(); | ||||
|  | ||||
| // better scoped exports | ||||
| import { resolve } from './dees-element.classes.resolvedirective.js'; | ||||
| import { subscribe } from './dees-element.classes.subscribedirective.js'; | ||||
|  | ||||
| export const directives = { | ||||
|   resolve, | ||||
|   subscribe, | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user