1 |
49598
|
stefanos.g
|
/**
|
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 type describing supported iterable types.
|
12 |
|
|
*
|
13 |
|
|
* @stable
|
14 |
|
|
*/
|
15 |
|
|
export declare type NgIterable<T> = Array<T> | Iterable<T>;
|
16 |
|
|
/**
|
17 |
|
|
* A strategy for tracking changes over time to an iterable. Used by {@link NgFor} to
|
18 |
|
|
* respond to changes in an iterable by effecting equivalent changes in the DOM.
|
19 |
|
|
*
|
20 |
|
|
* @stable
|
21 |
|
|
*/
|
22 |
|
|
export interface IterableDiffer<V> {
|
23 |
|
|
/**
|
24 |
|
|
* Compute a difference between the previous state and the new `object` state.
|
25 |
|
|
*
|
26 |
|
|
* @param object containing the new value.
|
27 |
|
|
* @returns an object describing the difference. The return value is only valid until the next
|
28 |
|
|
* `diff()` invocation.
|
29 |
|
|
*/
|
30 |
|
|
diff(object: NgIterable<V>): IterableChanges<V> | null;
|
31 |
|
|
}
|
32 |
|
|
/**
|
33 |
|
|
* An object describing the changes in the `Iterable` collection since last time
|
34 |
|
|
* `IterableDiffer#diff()` was invoked.
|
35 |
|
|
*
|
36 |
|
|
* @stable
|
37 |
|
|
*/
|
38 |
|
|
export interface IterableChanges<V> {
|
39 |
|
|
/**
|
40 |
|
|
* Iterate over all changes. `IterableChangeRecord` will contain information about changes
|
41 |
|
|
* to each item.
|
42 |
|
|
*/
|
43 |
|
|
forEachItem(fn: (record: IterableChangeRecord<V>) => void): void;
|
44 |
|
|
/**
|
45 |
|
|
* Iterate over a set of operations which when applied to the original `Iterable` will produce the
|
46 |
|
|
* new `Iterable`.
|
47 |
|
|
*
|
48 |
|
|
* NOTE: These are not necessarily the actual operations which were applied to the original
|
49 |
|
|
* `Iterable`, rather these are a set of computed operations which may not be the same as the
|
50 |
|
|
* ones applied.
|
51 |
|
|
*
|
52 |
|
|
* @param record A change which needs to be applied
|
53 |
|
|
* @param previousIndex The `IterableChangeRecord#previousIndex` of the `record` refers to the
|
54 |
|
|
* original `Iterable` location, where as `previousIndex` refers to the transient location
|
55 |
|
|
* of the item, after applying the operations up to this point.
|
56 |
|
|
* @param currentIndex The `IterableChangeRecord#currentIndex` of the `record` refers to the
|
57 |
|
|
* original `Iterable` location, where as `currentIndex` refers to the transient location
|
58 |
|
|
* of the item, after applying the operations up to this point.
|
59 |
|
|
*/
|
60 |
|
|
forEachOperation(fn: (record: IterableChangeRecord<V>, previousIndex: number, currentIndex: number) => void): void;
|
61 |
|
|
/**
|
62 |
|
|
* Iterate over changes in the order of original `Iterable` showing where the original items
|
63 |
|
|
* have moved.
|
64 |
|
|
*/
|
65 |
|
|
forEachPreviousItem(fn: (record: IterableChangeRecord<V>) => void): void;
|
66 |
|
|
/** Iterate over all added items. */
|
67 |
|
|
forEachAddedItem(fn: (record: IterableChangeRecord<V>) => void): void;
|
68 |
|
|
/** Iterate over all moved items. */
|
69 |
|
|
forEachMovedItem(fn: (record: IterableChangeRecord<V>) => void): void;
|
70 |
|
|
/** Iterate over all removed items. */
|
71 |
|
|
forEachRemovedItem(fn: (record: IterableChangeRecord<V>) => void): void;
|
72 |
|
|
/** Iterate over all items which had their identity (as computed by the `trackByFn`) changed. */
|
73 |
|
|
forEachIdentityChange(fn: (record: IterableChangeRecord<V>) => void): void;
|
74 |
|
|
}
|
75 |
|
|
/**
|
76 |
|
|
* Record representing the item change information.
|
77 |
|
|
*
|
78 |
|
|
* @stable
|
79 |
|
|
*/
|
80 |
|
|
export interface IterableChangeRecord<V> {
|
81 |
|
|
/** Current index of the item in `Iterable` or null if removed. */
|
82 |
|
|
readonly currentIndex: number | null;
|
83 |
|
|
/** Previous index of the item in `Iterable` or null if added. */
|
84 |
|
|
readonly previousIndex: number | null;
|
85 |
|
|
/** The item. */
|
86 |
|
|
readonly item: V;
|
87 |
|
|
/** Track by identity as computed by the `trackByFn`. */
|
88 |
|
|
readonly trackById: any;
|
89 |
|
|
}
|
90 |
|
|
/**
|
91 |
|
|
* @deprecated v4.0.0 - Use IterableChangeRecord instead.
|
92 |
|
|
*/
|
93 |
|
|
export interface CollectionChangeRecord<V> extends IterableChangeRecord<V> {
|
94 |
|
|
}
|
95 |
|
|
/**
|
96 |
|
|
* Nolonger used.
|
97 |
|
|
*
|
98 |
|
|
* @deprecated v4.0.0 - Use TrackByFunction instead
|
99 |
|
|
*/
|
100 |
|
|
export interface TrackByFn {
|
101 |
|
|
(index: number, item: any): any;
|
102 |
|
|
}
|
103 |
|
|
/**
|
104 |
|
|
* An optional function passed into {@link NgForOf} that defines how to track
|
105 |
|
|
* items in an iterable (e.g. fby index or id)
|
106 |
|
|
*
|
107 |
|
|
* @stable
|
108 |
|
|
*/
|
109 |
|
|
export interface TrackByFunction<T> {
|
110 |
|
|
(index: number, item: T): any;
|
111 |
|
|
}
|
112 |
|
|
/**
|
113 |
|
|
* Provides a factory for {@link IterableDiffer}.
|
114 |
|
|
*
|
115 |
|
|
* @stable
|
116 |
|
|
*/
|
117 |
|
|
export interface IterableDifferFactory {
|
118 |
|
|
supports(objects: any): boolean;
|
119 |
|
|
create<V>(trackByFn?: TrackByFunction<V>): IterableDiffer<V>;
|
120 |
|
|
/**
|
121 |
|
|
* @deprecated v4.0.0 - ChangeDetectorRef is not used and is no longer a parameter
|
122 |
|
|
*/
|
123 |
|
|
create<V>(_cdr?: ChangeDetectorRef | TrackByFunction<V>, trackByFn?: TrackByFunction<V>): IterableDiffer<V>;
|
124 |
|
|
}
|
125 |
|
|
/**
|
126 |
|
|
* A repository of different iterable diffing strategies used by NgFor, NgClass, and others.
|
127 |
|
|
* @stable
|
128 |
|
|
*/
|
129 |
|
|
export declare class IterableDiffers {
|
130 |
|
|
/**
|
131 |
|
|
* @deprecated v4.0.0 - Should be private
|
132 |
|
|
*/
|
133 |
|
|
factories: IterableDifferFactory[];
|
134 |
|
|
constructor(factories: IterableDifferFactory[]);
|
135 |
|
|
static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers;
|
136 |
|
|
/**
|
137 |
|
|
* Takes an array of {@link IterableDifferFactory} and returns a provider used to extend the
|
138 |
|
|
* inherited {@link IterableDiffers} instance with the provided factories and return a new
|
139 |
|
|
* {@link IterableDiffers} instance.
|
140 |
|
|
*
|
141 |
|
|
* The following example shows how to extend an existing list of factories,
|
142 |
|
|
* which will only be applied to the injector for this component and its children.
|
143 |
|
|
* This step is all that's required to make a new {@link IterableDiffer} available.
|
144 |
|
|
*
|
145 |
|
|
* ### Example
|
146 |
|
|
*
|
147 |
|
|
* ```
|
148 |
|
|
* @Component({
|
149 |
|
|
* viewProviders: [
|
150 |
|
|
* IterableDiffers.extend([new ImmutableListDiffer()])
|
151 |
|
|
* ]
|
152 |
|
|
* })
|
153 |
|
|
* ```
|
154 |
|
|
*/
|
155 |
|
|
static extend(factories: IterableDifferFactory[]): Provider;
|
156 |
|
|
find(iterable: any): IterableDifferFactory;
|
157 |
|
|
}
|
158 |
|
|
export declare function getTypeNameForDebugging(type: any): string;
|