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. When the reference of the expression changes, the `async` pipe
|
---|
47 | * automatically unsubscribes from the old `Observable` or `Promise` and subscribes to the new one.
|
---|
48 | *
|
---|
49 | * @usageNotes
|
---|
50 | *
|
---|
51 | * ### Examples
|
---|
52 | *
|
---|
53 | * This example binds a `Promise` to the view. Clicking the `Resolve` button resolves the
|
---|
54 | * promise.
|
---|
55 | *
|
---|
56 | * {@example common/pipes/ts/async_pipe.ts region='AsyncPipePromise'}
|
---|
57 | *
|
---|
58 | * It's also possible to use `async` with Observables. The example below binds the `time` Observable
|
---|
59 | * to the view. The Observable continuously updates the view with the current time.
|
---|
60 | *
|
---|
61 | * {@example common/pipes/ts/async_pipe.ts region='AsyncPipeObservable'}
|
---|
62 | *
|
---|
63 | * @publicApi
|
---|
64 | */
|
---|
65 | export class AsyncPipe {
|
---|
66 | constructor(_ref) {
|
---|
67 | this._ref = _ref;
|
---|
68 | this._latestValue = null;
|
---|
69 | this._subscription = null;
|
---|
70 | this._obj = null;
|
---|
71 | this._strategy = null;
|
---|
72 | }
|
---|
73 | ngOnDestroy() {
|
---|
74 | if (this._subscription) {
|
---|
75 | this._dispose();
|
---|
76 | }
|
---|
77 | }
|
---|
78 | transform(obj) {
|
---|
79 | if (!this._obj) {
|
---|
80 | if (obj) {
|
---|
81 | this._subscribe(obj);
|
---|
82 | }
|
---|
83 | return this._latestValue;
|
---|
84 | }
|
---|
85 | if (obj !== this._obj) {
|
---|
86 | this._dispose();
|
---|
87 | return this.transform(obj);
|
---|
88 | }
|
---|
89 | return this._latestValue;
|
---|
90 | }
|
---|
91 | _subscribe(obj) {
|
---|
92 | this._obj = obj;
|
---|
93 | this._strategy = this._selectStrategy(obj);
|
---|
94 | this._subscription = this._strategy.createSubscription(obj, (value) => this._updateLatestValue(obj, value));
|
---|
95 | }
|
---|
96 | _selectStrategy(obj) {
|
---|
97 | if (ɵisPromise(obj)) {
|
---|
98 | return _promiseStrategy;
|
---|
99 | }
|
---|
100 | if (ɵisSubscribable(obj)) {
|
---|
101 | return _subscribableStrategy;
|
---|
102 | }
|
---|
103 | throw invalidPipeArgumentError(AsyncPipe, obj);
|
---|
104 | }
|
---|
105 | _dispose() {
|
---|
106 | this._strategy.dispose(this._subscription);
|
---|
107 | this._latestValue = null;
|
---|
108 | this._subscription = null;
|
---|
109 | this._obj = null;
|
---|
110 | }
|
---|
111 | _updateLatestValue(async, value) {
|
---|
112 | if (async === this._obj) {
|
---|
113 | this._latestValue = value;
|
---|
114 | this._ref.markForCheck();
|
---|
115 | }
|
---|
116 | }
|
---|
117 | }
|
---|
118 | AsyncPipe.decorators = [
|
---|
119 | { type: Pipe, args: [{ name: 'async', pure: false },] }
|
---|
120 | ];
|
---|
121 | AsyncPipe.ctorParameters = () => [
|
---|
122 | { type: ChangeDetectorRef }
|
---|
123 | ];
|
---|
124 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXN5bmNfcGlwZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbW1vbi9zcmMvcGlwZXMvYXN5bmNfcGlwZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsaUJBQWlCLEVBQTJCLElBQUksRUFBaUIsVUFBVSxFQUFFLGVBQWUsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUczSCxPQUFPLEVBQUMsd0JBQXdCLEVBQUMsTUFBTSwrQkFBK0IsQ0FBQztBQVN2RSxNQUFNLG9CQUFvQjtJQUN4QixrQkFBa0IsQ0FBQyxLQUF3QixFQUFFLGlCQUFzQjtRQUNqRSxPQUFPLEtBQUssQ0FBQyxTQUFTLENBQUM7WUFDckIsSUFBSSxFQUFFLGlCQUFpQjtZQUN2QixLQUFLLEVBQUUsQ0FBQyxDQUFNLEVBQUUsRUFBRTtnQkFDaEIsTUFBTSxDQUFDLENBQUM7WUFDVixDQUFDO1NBQ0YsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztJQUVELE9BQU8sQ0FBQyxZQUE0QjtRQUNsQyxZQUFZLENBQUMsV0FBVyxFQUFFL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