Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active April 21, 2019 01:39
Show Gist options
  • Select an option

  • Save cartant/8b647725bdc705e6dbcb8f36e22ad60a to your computer and use it in GitHub Desktop.

Select an option

Save cartant/8b647725bdc705e6dbcb8f36e22ad60a to your computer and use it in GitHub Desktop.
import { Component, Input, OnInit, OnDestroy } from "@angular/core";
import { debounceTime, distinctUntilChanged, switchMapTo, takeUntil } from "rxjs/operators";
import { observe } from "rxjs-observe";
@Component({
selector: "some-component",
template: "<span>Some useless component that writes to the console</span>"
})
class SomeComponent implements OnInit, OnDestroy {
@Input() public name: string;
constructor() {
const { observables, proxy } = observe(this as SomeComponent);
observables.ngOnInit.pipe(
switchMapTo(observables.name),
debounceTime(400),
distinctUntilChanged(),
takeUntil(observables.ngOnDestroy)
).subscribe(value => console.log(value));
return proxy;
}
ngOnInit() {}
ngOnDestroy() {}
}
@ppowstanski
Copy link
Copy Markdown

Hmm ... implementation based on rxjs-observe looks really better. But why do you make presentation component tightly coupled with the store? The component becomes hard to reuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment