1
|
/**
|
2
|
* @license
|
3
|
* Copyright Google Inc. 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 { Provider } from '../../di';
|
9
|
import { ChangeDetectorRef } from '../change_detector_ref';
|
10
|
/**
|
11
|
* A differ that tracks changes made to an object over time.
|
12
|
*
|
13
|
* @stable
|
14
|
*/
|
15
|
export interface KeyValueDiffer<K, V> {
|
16
|
/**
|
17
|
* Compute a difference between the previous state and the new `object` state.
|
18
|
*
|
19
|
* @param object containing the new value.
|
20
|
* @returns an object describing the difference. The return value is only valid until the next
|
21
|
* `diff()` invocation.
|
22
|
*/
|
23
|
diff(object: Map<K, V>): KeyValueChanges<K, V>;
|
24
|
/**
|
25
|
* Compute a difference between the previous state and the new `object` state.
|
26
|
*
|
27
|
* @param object containing the new value.
|
28
|
* @returns an object describing the difference. The return value is only valid until the next
|
29
|
* `diff()` invocation.
|
30
|
*/
|
31
|
diff(object: {
|
32
|
[key: string]: V;
|
33
|
}): KeyValueChanges<string, V>;
|
34
|
}
|
35
|
/**
|
36
|
* An object describing the changes in the `Map` or `{[k:string]: string}` since last time
|
37
|
* `KeyValueDiffer#diff()` was invoked.
|
38
|
*
|
39
|
* @stable
|
40
|
*/
|
41
|
export interface KeyValueChanges<K, V> {
|
42
|
/**
|
43
|
* Iterate over all changes. `KeyValueChangeRecord` will contain information about changes
|
44
|
* to each item.
|
45
|
*/
|
46
|
forEachItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
|
47
|
/**
|
48
|
* Iterate over changes in the order of original Map showing where the original items
|
49
|
* have moved.
|
50
|
*/
|
51
|
forEachPreviousItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
|
52
|
/**
|
53
|
* Iterate over all keys for which values have changed.
|
54
|
*/
|
55
|
forEachChangedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
|
56
|
/**
|
57
|
* Iterate over all added items.
|
58
|
*/
|
59
|
forEachAddedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
|
60
|
/**
|
61
|
* Iterate over all removed items.
|
62
|
*/
|
63
|
forEachRemovedItem(fn: (r: KeyValueChangeRecord<K, V>) => void): void;
|
64
|
}
|
65
|
/**
|
66
|
* Record representing the item change information.
|
67
|
*
|
68
|
* @stable
|
69
|
*/
|
70
|
export interface KeyValueChangeRecord<K, V> {
|
71
|
/**
|
72
|
* Current key in the Map.
|
73
|
*/
|
74
|
readonly key: K;
|
75
|
/**
|
76
|
* Current value for the key or `null` if removed.
|
77
|
*/
|
78
|
readonly currentValue: V | null;
|
79
|
/**
|
80
|
* Previous value for the key or `null` if added.
|
81
|
*/
|
82
|
readonly previousValue: V | null;
|
83
|
}
|
84
|
/**
|
85
|
* Provides a factory for {@link KeyValueDiffer}.
|
86
|
*
|
87
|
* @stable
|
88
|
*/
|
89
|
export interface KeyValueDifferFactory {
|
90
|
/**
|
91
|
* Test to see if the differ knows how to diff this kind of object.
|
92
|
*/
|
93
|
supports(objects: any): boolean;
|
94
|
/**
|
95
|
* Create a `KeyValueDiffer`.
|
96
|
*/
|
97
|
create<K, V>(): KeyValueDiffer<K, V>;
|
98
|
/**
|
99
|
* @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter
|
100
|
*/
|
101
|
create<K, V>(_cdr?: ChangeDetectorRef): KeyValueDiffer<K, V>;
|
102
|
}
|
103
|
/**
|
104
|
* A repository of different Map diffing strategies used by NgClass, NgStyle, and others.
|
105
|
* @stable
|
106
|
*/
|
107
|
export declare class KeyValueDiffers {
|
108
|
/**
|
109
|
* @deprecated v4.0.0 - Should be private.
|
110
|
*/
|
111
|
factories: KeyValueDifferFactory[];
|
112
|
constructor(factories: KeyValueDifferFactory[]);
|
113
|
static create<S>(factories: KeyValueDifferFactory[], parent?: KeyValueDiffers): KeyValueDiffers;
|
114
|
/**
|
115
|
* Takes an array of {@link KeyValueDifferFactory} and returns a provider used to extend the
|
116
|
* inherited {@link KeyValueDiffers} instance with the provided factories and return a new
|
117
|
* {@link KeyValueDiffers} instance.
|
118
|
*
|
119
|
* The following example shows how to extend an existing list of factories,
|
120
|
* which will only be applied to the injector for this component and its children.
|
121
|
* This step is all that's required to make a new {@link KeyValueDiffer} available.
|
122
|
*
|
123
|
* ### Example
|
124
|
*
|
125
|
* ```
|
126
|
* @Component({
|
127
|
* viewProviders: [
|
128
|
* KeyValueDiffers.extend([new ImmutableMapDiffer()])
|
129
|
* ]
|
130
|
* })
|
131
|
* ```
|
132
|
*/
|
133
|
static extend<S>(factories: KeyValueDifferFactory[]): Provider;
|
134
|
find(kv: any): KeyValueDifferFactory;
|
135
|
}
|