Last active
April 21, 2019 01:39
-
-
Save cartant/8b647725bdc705e6dbcb8f36e22ad60a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm ... implementation based on
rxjs-observelooks really better. But why do you make presentation component tightly coupled with the store? The component becomes hard to reuse.