fix(dees-element): Refactor project structure and update dependency versions. Internal modules (e.g. dees-element classes and directives) have been reorganized and deprecated paths removed, and package.json now includes an updated packageManager field.
This commit is contained in:
40
ts/directives/classes.subscribedirective.ts
Normal file
40
ts/directives/classes.subscribedirective.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { noChange } from 'lit';
|
||||
import { AsyncDirective, directive } from 'lit/async-directive.js';
|
||||
import { rxjs } from '@push.rocks/smartrx';
|
||||
|
||||
/**
|
||||
* Subscribes to an observable
|
||||
*/
|
||||
class SubscribeDirective extends AsyncDirective {
|
||||
observable: rxjs.Observable<unknown> | undefined;
|
||||
sub: rxjs.Subscription | null = null;
|
||||
|
||||
render(observable: rxjs.Observable<unknown>) {
|
||||
if (this.observable !== observable) {
|
||||
this.sub?.unsubscribe();
|
||||
this.observable = observable;
|
||||
|
||||
if (this.isConnected) {
|
||||
this.subscribe(observable);
|
||||
}
|
||||
}
|
||||
|
||||
return noChange;
|
||||
}
|
||||
|
||||
subscribe(observable: rxjs.Observable<unknown>) {
|
||||
this.sub = observable.subscribe((v: unknown) => {
|
||||
this.setValue(v);
|
||||
});
|
||||
}
|
||||
|
||||
disconnected() {
|
||||
this.sub?.unsubscribe();
|
||||
}
|
||||
|
||||
reconnected() {
|
||||
this.subscribe(this.observable!);
|
||||
}
|
||||
}
|
||||
|
||||
export const subscribe = directive(SubscribeDirective);
|
Reference in New Issue
Block a user