@@ -17,31 +17,33 @@ angular.module('material.components.virtualRepeat', [
17
17
* @module material.components.virtualRepeat
18
18
* @restrict E
19
19
* @description
20
- * `md-virtual-repeat-container` provides the scroll container for md-virtual-repeat.
20
+ * `md-virtual-repeat-container` provides the scroll container for
21
+ * <a ng-href="api/directive/mdVirtualRepeat">md-virtual-repeat</a>.
21
22
*
22
- * VirtualRepeat is a limited substitute for ng-repeat that renders only
23
- * enough DOM nodes to fill the container and recycling them as the user scrolls.
23
+ * VirtualRepeat is a limited substitute for ` ng-repeat` that renders only
24
+ * enough DOM nodes to fill the container, recycling them as the user scrolls.
24
25
*
25
- * Once an element is not visible anymore, the VirtualRepeat recycles it and will reuse it for
26
- * another visible item by replacing the previous dataset with the new one.
26
+ * Once an element is not visible anymore, the Virtual Repeat recycles the element and reuses it
27
+ * for another visible item by replacing the previous data set with the set of currently visible
28
+ * elements.
27
29
*
28
30
* ### Common Issues
29
31
*
30
- * - When having one-time bindings inside of the view template, the VirtualRepeat will not properly
32
+ * - When having one-time bindings inside of the view template, the Virtual Repeat will not properly
31
33
* update the bindings for new items, since the view will be recycled.
32
- * - Directives inside of a VirtualRepeat will be only compiled (linked) once, because those
34
+ * - Directives inside of a Virtual Repeat will be only compiled (linked) once, because those
33
35
* items will be recycled and used for other items.
34
- * The VirtualRepeat just updates the scope bindings.
36
+ * The Virtual Repeat just updates the scope bindings.
35
37
*
36
38
*
37
39
* ### Notes
38
40
*
39
41
* > The VirtualRepeat is a similar implementation to the Android
40
- * [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html)
42
+ * [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html).
41
43
*
42
44
* <!-- This comment forces a break between blockquotes //-->
43
45
*
44
- * > Please also review the <a ng-href="api/directive/mdVirtualRepeat">VirtualRepeat </a>
46
+ * > Please also review the <a ng-href="api/directive/mdVirtualRepeat">mdVirtualRepeat </a>
45
47
* documentation for more information.
46
48
*
47
49
*
@@ -53,14 +55,14 @@ angular.module('material.components.virtualRepeat', [
53
55
* </md-virtual-repeat-container>
54
56
* </hljs>
55
57
*
58
+ * @param {boolean= } md-auto-shrink When present and the container will shrink to fit
59
+ * the number of items in the `md-virtual-repeat`.
60
+ * @param {number= } md-auto-shrink-min Minimum number of items that md-auto-shrink
61
+ * will shrink to. Default: `0`.
62
+ * @param {boolean= } md-orient-horizontal Whether the container should scroll horizontally.
63
+ * The default is `false` which indicates vertical orientation and scrolling.
56
64
* @param {number= } md-top-index Binds the index of the item that is at the top of the scroll
57
65
* container to `$scope`. It can both read and set the scroll position.
58
- * @param {boolean= } md-orient-horizontal Whether the container should scroll horizontally
59
- * (defaults to orientation and scrolling vertically).
60
- * @param {boolean= } md-auto-shrink When present, the container will shrink to fit
61
- * the number of items when that number is less than its original size.
62
- * @param {number= } md-auto-shrink-min Minimum number of items that md-auto-shrink
63
- * will shrink to (default: 0).
64
66
*/
65
67
function VirtualRepeatContainerDirective ( ) {
66
68
return {
@@ -148,7 +150,7 @@ function VirtualRepeatContainerController($$rAF, $mdUtil, $mdConstant, $parse, $
148
150
this . sizer = this . scroller . querySelector ( '.md-virtual-repeat-sizer' ) ;
149
151
this . offsetter = this . scroller . querySelector ( '.md-virtual-repeat-offsetter' ) ;
150
152
151
- // After the dom stablizes , measure the initial size of the container and
153
+ // After the DOM stabilizes , measure the initial size of the container and
152
154
// make a best effort at re-measuring as it changes.
153
155
var boundUpdateSize = angular . bind ( this , this . updateSize ) ;
154
156
@@ -418,18 +420,23 @@ VirtualRepeatContainerController.prototype.handleScroll_ = function() {
418
420
* @restrict A
419
421
* @priority 1000
420
422
* @description
421
- * `md-virtual-repeat` specifies an element to repeat using virtual scrolling.
423
+ * The `md-virtual-repeat` attribute is applied to a template that is repeated using virtual
424
+ * scrolling. This provides smooth and performant scrolling through very large lists of elements.
425
+ *
426
+ * Virtual repeat is a limited substitute for `ng-repeat` that renders only
427
+ * enough DOM nodes to fill the container, recycling them as the user scrolls.
422
428
*
423
- * Virtual repeat is a limited substitute for ng-repeat that renders only
424
- * enough DOM nodes to fill the container and recycling them as the user scrolls.
429
+ * ### Notes
425
430
*
426
- * Arrays, but not objects are supported for iteration.
427
- * Track by, as alias, and (key, value) syntax are not supported.
431
+ * - Arrays are supported for iteration by default.
432
+ * - An object can used use if `md-on-demand` is specified and the object implements the interface
433
+ * described in the `md-on-demand` <a ng-href="#attributes">documentation</a>.
434
+ * - `trackBy`, `as` alias, and `(key, value)` syntax from `ng-repeat` are not supported.
428
435
*
429
436
* ### On-Demand Async Item Loading
430
437
*
431
- * When using the `md-on-demand` attribute and loading some asynchronous data, the `getItemAtIndex` function will
432
- * mostly return nothing.
438
+ * When using the `md-on-demand` attribute and loading some asynchronous data,
439
+ * the `getItemAtIndex` function will mostly return nothing.
433
440
*
434
441
* <hljs lang="js">
435
442
* DynamicItems.prototype.getItemAtIndex = function(index) {
@@ -442,10 +449,10 @@ VirtualRepeatContainerController.prototype.handleScroll_ = function() {
442
449
* };
443
450
* </hljs>
444
451
*
445
- * This means that the VirtualRepeat will not have any value for the given index.<br/>
446
- * After the data loading completed , the user expects the VirtualRepeat to recognize the change.
452
+ * This means that the Virtual Repeat will not have any value for the given index.<br/>
453
+ * After the data loading completes , the user expects the Virtual Repeat to recognize the change.
447
454
*
448
- * To make sure that the VirtualRepeat properly detects any change, you need to run the operation
455
+ * To make sure that the Virtual Repeat properly detects any change, you need to run the operation
449
456
* in another digest.
450
457
*
451
458
* <hljs lang="js">
@@ -474,19 +481,20 @@ VirtualRepeatContainerController.prototype.handleScroll_ = function() {
474
481
* </md-virtual-repeat-container>
475
482
* </hljs>
476
483
*
477
- * @param {number= } md-item-size The height or width of the repeated elements (which must be
478
- * identical for each element). Optional. Will attempt to read the size from the dom if missing,
479
- * but still assumes that all repeated nodes have same height or width.
480
- * @param {string= } md-extra-name Evaluates to an additional name to which the current iterated item
484
+ * @param {expression= } md-extra-name Evaluates to an additional name to which the current iterated item
481
485
* can be assigned on the repeated scope (needed for use in `md-autocomplete`).
482
- * @param {boolean= } md-on-demand When present, treats the md-virtual-repeat argument as an object
486
+ * @param {number= } md-item-size Optional height or width of the repeated elements (which **must be
487
+ * identical for each element**). Virtual repeat will attempt to read the size from the DOM,
488
+ * if missing, but it still assumes that all repeated nodes have the **same height**
489
+ * (when scrolling vertically) or **same width** (when scrolling horizontally).
490
+ * @param {boolean= } md-on-demand When present, treats the `md-virtual-repeat` argument as an object
483
491
* that can fetch rows rather than an array.
484
492
*
485
- * **NOTE:** This object must implement the following interface with two (2) methods:
493
+ * **NOTE:** This object ** must** implement the following interface with two methods:
486
494
*
487
- * - `getItemAtIndex: function(index) [object]` The item at that index or null if it is not yet
488
- * loaded (it should start downloading the item in that case).
489
- * - `getLength: function() [ number]` The data length to which the repeater container
495
+ * - `getItemAtIndex` - `{ function(index): Object}`: The item at that ` index` or ` null` if it is not
496
+ * yet loaded (it should start downloading the item in that case).
497
+ * - `getLength` - `{ function(): number}`: The data length to which the repeater container
490
498
* should be sized. Ideally, when the count is known, this method should return it.
491
499
* Otherwise, return a higher number than the currently loaded items to produce an
492
500
* infinite-scroll behavior.
@@ -540,8 +548,6 @@ function VirtualRepeatController($scope, $element, $attrs, $browser, $document,
540
548
this . startIndex = 0 ;
541
549
/** @type {number } Previous ending repeat index (based on scroll offset) */
542
550
this . endIndex = 0 ;
543
- // TODO: measure width/height of first element from dom if not provided.
544
- // getComputedStyle?
545
551
/** @type {?number } Height/width of repeated elements. */
546
552
this . itemSize = $scope . $eval ( $attrs . mdItemSize ) || null ;
547
553
@@ -565,7 +571,7 @@ function VirtualRepeatController($scope, $element, $attrs, $browser, $document,
565
571
566
572
/**
567
573
* Presently rendered blocks by repeat index.
568
- * @type {Object<number, !VirtualRepeatController.Block }
574
+ * @type {Object<number, !VirtualRepeatController.Block> }
569
575
*/
570
576
this . blocks = { } ;
571
577
/** @type {Array<!VirtualRepeatController.Block> } A pool of presently unused blocks. */
@@ -661,7 +667,7 @@ VirtualRepeatController.prototype.repeatListExpression_ = function(scope) {
661
667
662
668
663
669
/**
664
- * Called by the container. Informs us that the containers scroll or size has
670
+ * Called by the container. Informs us that the container's scroll or size has
665
671
* changed.
666
672
*/
667
673
VirtualRepeatController . prototype . containerUpdated = function ( ) {
@@ -711,16 +717,16 @@ VirtualRepeatController.prototype.containerUpdated = function() {
711
717
712
718
/**
713
719
* Called by the container. Returns the size of a single repeated item.
714
- * @return {?number } Size of a repeated item.
720
+ * @return {?number } size of a repeated item.
715
721
*/
716
722
VirtualRepeatController . prototype . getItemSize = function ( ) {
717
723
return this . itemSize ;
718
724
} ;
719
725
720
726
721
727
/**
722
- * Called by the container. Returns the size of a single repeated item.
723
- * @return {?number } Size of a repeated item .
728
+ * Called by the container.
729
+ * @return {?number } the most recently seen length of items .
724
730
*/
725
731
VirtualRepeatController . prototype . getItemCount = function ( ) {
726
732
return this . itemsLength ;
@@ -729,7 +735,9 @@ VirtualRepeatController.prototype.getItemCount = function() {
729
735
730
736
/**
731
737
* Updates the order and visible offset of repeated blocks in response to scrolling
732
- * or items updates.
738
+ * or updates to `items`.
739
+ * @param items {Array} visible elements
740
+ * @param oldItems {Array} previously visible elements
733
741
* @private
734
742
*/
735
743
VirtualRepeatController . prototype . virtualRepeatUpdate_ = function ( items , oldItems ) {
@@ -882,8 +890,8 @@ VirtualRepeatController.prototype.updateBlock_ = function(block, index) {
882
890
this . updateScope_ ( block . scope , index ) ;
883
891
884
892
// Perform digest before reattaching the block.
885
- // Any resulting synchronous dom mutations should be much faster as a result.
886
- // This might break some directives, but I'm going to try it for now .
893
+ // Any resulting synchronous DOM mutations should be much faster as a result.
894
+ // This might break some directives.
887
895
if ( ! this . $rootScope . $$phase ) {
888
896
block . scope . $digest ( ) ;
889
897
}
@@ -997,8 +1005,12 @@ VirtualRepeatModelArrayLike.prototype.$$includeIndexes = function(start, end) {
997
1005
* @restrict A
998
1006
* @description
999
1007
*
1000
- * Force an element to have a certain px height. This is used in place of a style tag in order to
1001
- * conform to the Content Security Policy regarding unsafe-inline style tags.
1008
+ * Force an element to have a certain `px` height. This is used in place of a style tag in order to
1009
+ * conform to the
1010
+ * <a href="https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy/script-src">
1011
+ * Content Security Policy</a> regarding `unsafe-inline` `<style>` tags.
1012
+ *
1013
+ * This directive is related to <a ng-href="api/directive/mdVirtualRepeat">mdVirtualRepeat</a>.
1002
1014
*
1003
1015
* @usage
1004
1016
* <hljs lang="html">
0 commit comments