1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { ChangeDetectorRef, Pipe, ɵisPromise, ɵisSubscribable } from '@angular/core';
|
---|
9 | import { invalidPipeArgumentError } from './invalid_pipe_argument_error';
|
---|
10 | class SubscribableStrategy {
|
---|
11 | createSubscription(async, updateLatestValue) {
|
---|
12 | return async.subscribe({
|
---|
13 | next: updateLatestValue,
|
---|
14 | error: (e) => {
|
---|
15 | throw e;
|
---|
16 | }
|
---|
17 | });
|
---|
18 | }
|
---|
19 | dispose(subscription) {
|
---|
20 | subscription.unsubscribe();
|
---|
21 | }
|
---|
22 | onDestroy(subscription) {
|
---|
23 | subscription.unsubscribe();
|
---|
24 | }
|
---|
25 | }
|
---|
26 | class PromiseStrategy {
|
---|
27 | createSubscription(async, updateLatestValue) {
|
---|
28 | return async.then(updateLatestValue, e => {
|
---|
29 | throw e;
|
---|
30 | });
|
---|
31 | }
|
---|
32 | dispose(subscription) { }
|
---|
33 | onDestroy(subscription) { }
|
---|
34 | }
|
---|
35 | const _promiseStrategy = new PromiseStrategy();
|
---|
36 | const _subscribableStrategy = new SubscribableStrategy();
|
---|
37 | /**
|
---|
38 | * @ngModule CommonModule
|
---|
39 | * @description
|
---|
40 | *
|
---|
41 | * Unwraps a value from an asynchronous primitive.
|
---|
42 | *
|
---|
43 | * The `async` pipe subscribes to an `Observable` or `Promise` and returns the latest value it has
|
---|
44 | * emitted. When a new value is emitted, the `async` pipe marks the component to be checked for
|
---|
45 | * changes. When the component gets destroyed, the `async` pipe unsubscribes automatically to avoid
|
---|
46 | * potential memory leaks.
|
---|
47 | *
|
---|
48 | * @usageNotes
|
---|
49 | *
|
---|
50 | * ### Examples
|
---|
51 | *
|
---|
52 | * This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the
|
---|
53 | * promise.
|
---|
54 | *
|
---|
55 | * {@example common/pipes/ts/async_pipe.ts region='AsyncPipePromise'}
|
---|
56 | *
|
---|
57 | * It's also possible to use `async` with Observables. The example below binds the `time` Observable
|
---|
58 | * to the view. The Observable continuously updates the view with the current time.
|
---|
59 | *
|
---|
60 | * {@example common/pipes/ts/async_pipe.ts region='AsyncPipeObservable'}
|
---|
61 | *
|
---|
62 | * @publicApi
|
---|
63 | */
|
---|
64 | export class AsyncPipe {
|
---|
65 | constructor(_ref) {
|
---|
66 | this._ref = _ref;
|
---|
67 | this._latestValue = null;
|
---|
68 | this._subscription = null;
|
---|
69 | this._obj = null;
|
---|
70 | this._strategy = null;
|
---|
71 | }
|
---|
72 | ngOnDestroy() {
|
---|
73 | if (this._subscription) {
|
---|
74 | this._dispose();
|
---|
75 | }
|
---|
76 | }
|
---|
77 | transform(obj) {
|
---|
78 | if (!this._obj) {
|
---|
79 | if (obj) {
|
---|
80 | this._subscribe(obj);
|
---|
81 | }
|
---|
82 | return this._latestValue;
|
---|
83 | }
|
---|
84 | if (obj !== this._obj) {
|
---|
85 | this._dispose();
|
---|
86 | return this.transform(obj);
|
---|
87 | }
|
---|
88 | return this._latestValue;
|
---|
89 | }
|
---|
90 | _subscribe(obj) {
|
---|
91 | this._obj = obj;
|
---|
92 | this._strategy = this._selectStrategy(obj);
|
---|
93 | this._subscription = this._strategy.createSubscription(obj, (value) => this._updateLatestValue(obj, value));
|
---|
94 | }
|
---|
95 | _selectStrategy(obj) {
|
---|
96 | if (ɵisPromise(obj)) {
|
---|
97 | return _promiseStrategy;
|
---|
98 | }
|
---|
99 | if (ɵisSubscribable(obj)) {
|
---|
100 | return _subscribableStrategy;
|
---|
101 | }
|
---|
102 | throw invalidPipeArgumentError(AsyncPipe, obj);
|
---|
103 | }
|
---|
104 | _dispose() {
|
---|
105 | this._strategy.dispose(this._subscription);
|
---|
106 | this._latestValue = null;
|
---|
107 | this._subscription = null;
|
---|
108 | this._obj = null;
|
---|
109 | }
|
---|
110 | _updateLatestValue(async, value) {
|
---|
111 | if (async === this._obj) {
|
---|
112 | this._latestValue = value;
|
---|
113 | this._ref.markForCheck();
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|
117 | AsyncPipe.decorators = [
|
---|
118 | { type: Pipe, args: [{ name: 'async', pure: false },] }
|
---|
119 | ];
|
---|
120 | AsyncPipe.ctorParameters = () => [
|
---|
121 | { type: ChangeDetectorRef }
|
---|
122 | ];
|
---|
123 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXN5bmNfcGlwZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbW1vbi9zcmMvcGlwZXMvYXN5bmNfcGlwZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsaUJBQWlCLEVBQTJCLElBQUksRUFBaUIsVUFBVSxFQUFFLGVBQWUsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUczSCxPQUFPLEVBQUMsd0JBQXdCLEVBQUMsTUFBTSwrQkFBK0IsQ0FBQztBQVN2RSxNQUFNLG9CQUFvQjtJQUN4QixrQkFBa0IsQ0FBQyxLQUF3QixFQUFFLGlCQUFzQjtRQUNqRSxPQUFPLEtBQUssQ0FBQyxTQUFTLENBQUM7WUFDckIsSUFBSSxFQUFFLGlCQUFpQjtZQUN2QixLQUFLLEVBQUUsQ0FBQyxDQUFNLEVBQUUsRUFBRTtnQkFDaEIsTUFBTSxDQUFDLENBQUM7WUFDVixDQUFDO1NBQ0YsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztJQUVELE9BQU8sQ0FBQyxZQUE0QjtRQUNsQyxZQUFZLENBQUMsV0FBVyxFQUFFLENBQUM7SUFDN0IsQ0FBQztJQUVELFNBQVMsQ0FBQyxZQUE0QjtRQUNwQyxZQUF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