-
Notifications
You must be signed in to change notification settings - Fork 2k
/
dom-repeat.d.ts
282 lines (262 loc) · 10.6 KB
/
dom-repeat.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* lib/elements/dom-repeat.html
*/
/// <reference path="../../polymer-element.d.ts" />
/// <reference path="../utils/templatize.d.ts" />
/// <reference path="../utils/debounce.d.ts" />
/// <reference path="../utils/flush.d.ts" />
/// <reference path="../mixins/mutable-data.d.ts" />
declare namespace Polymer {
/**
* The `<dom-repeat>` element will automatically stamp and binds one instance
* of template content to each object in a user-provided array.
* `dom-repeat` accepts an `items` property, and one instance of the template
* is stamped for each item into the DOM at the location of the `dom-repeat`
* element. The `item` property will be set on each instance's binding
* scope, thus templates should bind to sub-properties of `item`.
*
* Example:
*
* ```html
* <dom-module id="employee-list">
*
* <template>
*
* <div> Employee list: </div>
* <dom-repeat items="{{employees}}">
* <template>
* <div>First name: <span>{{item.first}}</span></div>
* <div>Last name: <span>{{item.last}}</span></div>
* </template>
* </dom-repeat>
*
* </template>
*
* </dom-module>
* ```
*
* With the following custom element definition:
*
* ```js
* class EmployeeList extends Polymer.Element {
* static get is() { return 'employee-list'; }
* static get properties() {
* return {
* employees: {
* value() {
* return [
* {first: 'Bob', last: 'Smith'},
* {first: 'Sally', last: 'Johnson'},
* ...
* ];
* }
* }
* };
* }
* }
* ```
*
* Notifications for changes to items sub-properties will be forwarded to template
* instances, which will update via the normal structured data notification system.
*
* Mutations to the `items` array itself should be made using the Array
* mutation API's on `Polymer.Base` (`push`, `pop`, `splice`, `shift`,
* `unshift`), and template instances will be kept in sync with the data in the
* array.
*
* Events caught by event handlers within the `dom-repeat` template will be
* decorated with a `model` property, which represents the binding scope for
* each template instance. The model is an instance of Polymer.Base, and should
* be used to manipulate data on the instance, for example
* `event.model.set('item.checked', true);`.
*
* Alternatively, the model for a template instance for an element stamped by
* a `dom-repeat` can be obtained using the `modelForElement` API on the
* `dom-repeat` that stamped it, for example
* `this.$.domRepeat.modelForElement(event.target).set('item.checked', true);`.
* This may be useful for manipulating instance data of event targets obtained
* by event handlers on parents of the `dom-repeat` (event delegation).
*
* A view-specific filter/sort may be applied to each `dom-repeat` by supplying a
* `filter` and/or `sort` property. This may be a string that names a function on
* the host, or a function may be assigned to the property directly. The functions
* should implemented following the standard `Array` filter/sort API.
*
* In order to re-run the filter or sort functions based on changes to sub-fields
* of `items`, the `observe` property may be set as a space-separated list of
* `item` sub-fields that should cause a re-filter/sort when modified. If
* the filter or sort function depends on properties not contained in `items`,
* the user should observe changes to those properties and call `render` to update
* the view based on the dependency change.
*
* For example, for an `dom-repeat` with a filter of the following:
*
* ```js
* isEngineer(item) {
* return item.type == 'engineer' || item.manager.type == 'engineer';
* }
* ```
*
* Then the `observe` property should be configured as follows:
*
* ```html
* <dom-repeat items="{{employees}}" filter="isEngineer" observe="type manager.type">
* ```
*/
class DomRepeat extends
Polymer.OptionalMutableData(
Polymer.Element) {
/**
* An array containing items determining how many instances of the template
* to stamp and that that each template instance should bind to.
*/
items: any[]|null|undefined;
/**
* The name of the variable to add to the binding scope for the array
* element associated with a given template instance.
*/
as: string|null|undefined;
/**
* The name of the variable to add to the binding scope with the index
* of the instance in the sorted and filtered list of rendered items.
* Note, for the index in the `this.items` array, use the value of the
* `itemsIndexAs` property.
*/
indexAs: string|null|undefined;
/**
* The name of the variable to add to the binding scope with the index
* of the instance in the `this.items` array. Note, for the index of
* this instance in the sorted and filtered list of rendered items,
* use the value of the `indexAs` property.
*/
itemsIndexAs: string|null|undefined;
/**
* A function that should determine the sort order of the items. This
* property should either be provided as a string, indicating a method
* name on the element's host, or else be an actual function. The
* function should match the sort function passed to `Array.sort`.
* Using a sort function has no effect on the underlying `items` array.
*/
sort: Function|null|undefined;
/**
* A function that can be used to filter items out of the view. This
* property should either be provided as a string, indicating a method
* name on the element's host, or else be an actual function. The
* function should match the sort function passed to `Array.filter`.
* Using a filter function has no effect on the underlying `items` array.
*/
filter: Function|null|undefined;
/**
* When using a `filter` or `sort` function, the `observe` property
* should be set to a space-separated list of the names of item
* sub-fields that should trigger a re-sort or re-filter when changed.
* These should generally be fields of `item` that the sort or filter
* function depends on.
*/
observe: string|null|undefined;
/**
* When using a `filter` or `sort` function, the `delay` property
* determines a debounce time in ms after a change to observed item
* properties that must pass before the filter or sort is re-run.
* This is useful in rate-limiting shuffling of the view when
* item changes may be frequent.
*/
delay: number|null|undefined;
/**
* Count of currently rendered items after `filter` (if any) has been applied.
* If "chunking mode" is enabled, `renderedItemCount` is updated each time a
* set of template instances is rendered.
*/
readonly renderedItemCount: number|null|undefined;
/**
* Defines an initial count of template instances to render after setting
* the `items` array, before the next paint, and puts the `dom-repeat`
* into "chunking mode". The remaining items will be created and rendered
* incrementally at each animation frame therof until all instances have
* been rendered.
*/
initialCount: number|null|undefined;
/**
* When `initialCount` is used, this property defines a frame rate (in
* fps) to target by throttling the number of instances rendered each
* frame to not exceed the budget for the target frame rate. The
* framerate is effectively the number of `requestAnimationFrame`s that
* it tries to allow to actually fire in a given second. It does this
* by measuring the time between `rAF`s and continuously adjusting the
* number of items created each `rAF` to maintain the target framerate.
* Setting this to a higher number allows lower latency and higher
* throughput for event handlers and other tasks, but results in a
* longer time for the remaining items to complete rendering.
*/
targetFramerate: number|null|undefined;
readonly _targetFrameTime: number|null|undefined;
connectedCallback(): void;
disconnectedCallback(): void;
/**
* Forces the element to render its content. Normally rendering is
* asynchronous to a provoking change. This is done for efficiency so
* that multiple changes trigger only a single render. The render method
* should be called if, for example, template rendering is required to
* validate application state.
*/
render(): void;
/**
* Shows or hides the template instance top level child elements. For
* text nodes, `textContent` is removed while "hidden" and replaced when
* "shown."
*
* @param hidden Set to true to hide the children;
* set to false to show them.
*/
_showHideChildren(hidden: boolean): void;
/**
* Returns the item associated with a given element stamped by
* this `dom-repeat`.
*
* Note, to modify sub-properties of the item,
* `modelForElement(el).set('item.<sub-prop>', value)`
* should be used.
*
* @param el Element for which to return the item.
* @returns Item associated with the element.
*/
itemForElement(el: HTMLElement): any;
/**
* Returns the inst index for a given element stamped by this `dom-repeat`.
* If `sort` is provided, the index will reflect the sorted order (rather
* than the original array order).
*
* @param el Element for which to return the index.
* @returns Row index associated with the element (note this may
* not correspond to the array index if a user `sort` is applied).
*/
indexForElement(el: HTMLElement): number|null;
/**
* Returns the template "model" associated with a given element, which
* serves as the binding scope for the template instance the element is
* contained in. A template model is an instance of `Polymer.Base`, and
* should be used to manipulate data associated with this template instance.
*
* Example:
*
* let model = modelForElement(el);
* if (model.index < 10) {
* model.set('item.checked', true);
* }
*
* @param el Element for which to return a template model.
* @returns Model representing the binding scope for
* the element.
*/
modelForElement(el: HTMLElement): TemplateInstanceBase|null;
}
}
interface HTMLElementTagNameMap {
"dom-repeat": Polymer.DomRepeat;
}