This file contains 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
const example1$ = from(people).pipe(map(person => person.house.street)); | |
const example2$ = from(people).pipe(pluck('house', 'street')); |
This file contains 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
pay$ = defer(() => fromEvent(button, 'click')).pipe( | |
mergeMap(() => this.payService.pay() | |
// This will make the above fire multiple times regardless if there is one currently running | |
); | |
ngOnInit() { | |
this.pay$.subscribe() | |
} |
This file contains 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
start() { | |
documentSubscription$ = fromEvent(document, 'click').subscribe(); | |
// this is our addEventListener | |
} | |
done() { | |
this.documentSubscription$.unsubscribe(); | |
// this is our removeEventListener | |
} |
This file contains 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
@ViewChild('button', {static: true }) buttonElement: ElementRef<HTMLButtonElement>; | |
clicks$ = defer(() => fromEvent(this.buttonElement.nativeElement, "clicks")).pipe( | |
map(() => new Date().toString()), | |
tap(console.log) | |
); | |
ngOnInit() { | |
this.clicks$.subscribe(); | |
// Works! |
This file contains 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
@ViewChild('button', {static: true }) buttonElement: ElementRef<HTMLButtonElement>; | |
clicks$ = fromEvent(this.buttonElement.nativeElement, "click").pipe( | |
map(() => new Date().toString()), | |
tap(console.log) | |
); | |
ngOnInit() { | |
this.clicks$.subscribe(); | |
// ERROR |
This file contains 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
const example1$ = from(people).pipe(map(person => person.name)); | |
const example2$ = from(people).pipe(pluck('name')); |
This file contains 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
const people: Array<Person> = [ | |
{ | |
name: 'Jill', | |
house: { | |
street: RxJs Street, | |
number: 20, | |
size: 1100 | |
} | |
}, | |
{ |
This file contains 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
export interface Person { | |
name: string; | |
house: House; | |
} | |
export interface House { | |
street: string; | |
number: number; | |
size: number; | |
} |
This file contains 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
getProductIfExist$ = (productId: string) => { | |
return this.store | |
.select(fromProduct.getProductById(productId)) | |
.pipe(filter(product => !!product)); | |
}; | |
getProductFromApi$ = (id: string) => | |
this.getProductIfExist$(id).pipe( | |
filter(product => !product), | |
switchMap(() => this.productService.getProduct(id)) |
This file contains 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
@Component({ | |
selector: 'my-app', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent implements OnInit { | |
@ViewChild('dropZone', { static: true }) dropZone: ElementRef<HTMLDivElement>; | |
dragEnter$ = defer(() => fromEvent(this.dropZone.nativeElement, 'dragenter')).pipe( |
NewerOlder