This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial checkin. Need to test it out now.
demo works dynamic loading demo WiP. comments comment Add a comment for method. jeremy's suggestion
- Loading branch information
Showing
7 changed files
with
269 additions
and
3 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/components/virtualRepeat/demoDeferredLoading/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div ng-controller="AppCtrl as ctrl"> | ||
<md-content layout="column"> | ||
<p> | ||
Display a list of 50,000 items that load on demand in a viewport of only 7 rows (height=40px). | ||
<br/><br/> | ||
This demo shows scroll and rendering performance gains when using <code>md-virtual-repeat</code>; | ||
achieved with the dynamic reuse of rows visible in the viewport area. Developers are required to | ||
explicitly use <code>md-virtual-repeat-container</code> as a wrapping parent container. | ||
<br/><br/> | ||
To enable load-on-demand behavior, developers must pass in a custom instance of | ||
mdVirtualRepeatModel (see the example's source for more info). | ||
</p> | ||
|
||
<md-virtual-repeat-container id="vertical-container"> | ||
<div md-virtual-repeat="item in ctrl.dynamicItems" md-on-demand | ||
class="repeated-item" flex> | ||
{{item}} | ||
</div> | ||
</md-virtual-repeat-container> | ||
</md-content> | ||
|
||
</div> |
70 changes: 70 additions & 0 deletions
70
src/components/virtualRepeat/demoDeferredLoading/script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('virtualRepeatDeferredLoadingDemo', ['ngMaterial']) | ||
.controller('AppCtrl', function($timeout) { | ||
|
||
// In this example, we set up our model using a class. | ||
// Using a plain object works too. All that matters | ||
// is that we implement getItemAtIndex and getLength. | ||
var DynamicItems = function() { | ||
/** | ||
* @type {!Object<?Array>} Data pages, keyed by page number (0-index). | ||
*/ | ||
this.loadedPages = {}; | ||
|
||
/** @type {number} Total number of items. */ | ||
this.numItems = 0; | ||
|
||
/** @const {number} Number of items to fetch per request. */ | ||
this.PAGE_SIZE = 50; | ||
|
||
this.fetchNumItems_(); | ||
}; | ||
|
||
// Required. | ||
DynamicItems.prototype.getItemAtIndex = function(index) { | ||
var pageNumber = Math.floor(index / this.PAGE_SIZE); | ||
var page = this.loadedPages[pageNumber]; | ||
|
||
if (page) { | ||
return page[index % this.PAGE_SIZE]; | ||
} else if (page !== null) { | ||
this.fetchPage_(pageNumber); | ||
} | ||
}; | ||
|
||
// Required. | ||
DynamicItems.prototype.getLength = function() { | ||
return this.numItems; | ||
}; | ||
|
||
DynamicItems.prototype.fetchPage_ = function(pageNumber) { | ||
// Set the page to null so we know it is already being fetched. | ||
this.loadedPages[pageNumber] = null; | ||
|
||
// For demo purposes, we simulate loading more items with a timed | ||
// promise. In real code, this function would likely contain an | ||
// $http request. | ||
$timeout(angular.noop, 300).then(angular.bind(this, function() { | ||
this.loadedPages[pageNumber] = []; | ||
var pageOffset = pageNumber * this.PAGE_SIZE; | ||
for (var i = pageOffset; i < pageOffset + this.PAGE_SIZE; i++) { | ||
this.loadedPages[pageNumber].push(i); | ||
} | ||
})); | ||
}; | ||
|
||
DynamicItems.prototype.fetchNumItems_ = function() { | ||
// For demo purposes, we simulate loading the item count with a timed | ||
// promise. In real code, this function would likely contain an | ||
// $http request. | ||
$timeout(angular.noop, 300).then(angular.bind(this, function() { | ||
this.numItems = 50000; | ||
})); | ||
}; | ||
|
||
this.dynamicItems = new DynamicItems(); | ||
}); | ||
})(); |
23 changes: 23 additions & 0 deletions
23
src/components/virtualRepeat/demoDeferredLoading/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#vertical-container { | ||
height: 292px; | ||
width: 400px; | ||
} | ||
|
||
.repeated-item { | ||
border-bottom: 1px solid #ddd; | ||
box-sizing: border-box; | ||
height: 40px; | ||
padding-top: 10px; | ||
} | ||
|
||
md-content { | ||
margin: 16px; | ||
} | ||
|
||
md-virtual-repeat-container { | ||
border: solid 1px grey; | ||
} | ||
|
||
.md-virtual-repeat-container .md-virtual-repeat-offsetter { | ||
padding-left: 16px; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/components/virtualRepeat/demoInfiniteScroll/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div ng-controller="AppCtrl as ctrl"> | ||
<md-content layout="column"> | ||
<p> | ||
Display an infinitely growing list of items in a viewport of only 7 rows (height=40px). | ||
<br/><br/> | ||
This demo shows scroll and rendering performance gains when using <code>md-virtual-repeat</code>; | ||
achieved with the dynamic reuse of rows visible in the viewport area. Developers are required to | ||
explicitly use <code>md-virtual-repeat-container</code> as a wrapping parent container. | ||
<br/><br/> | ||
To enable infinite scroll behavior, developers must pass in a custom instance of | ||
mdVirtualRepeatModel (see the example's source for more info). | ||
</p> | ||
|
||
<md-virtual-repeat-container id="vertical-container"> | ||
<div md-virtual-repeat="item in ctrl.infiniteItems" md-on-demand | ||
class="repeated-item" flex> | ||
{{item}} | ||
</div> | ||
</md-virtual-repeat-container> | ||
</md-content> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('virtualRepeatInfiniteScrollDemo', ['ngMaterial']) | ||
.controller('AppCtrl', function($timeout) { | ||
|
||
// In this example, we set up our model using a plain object. | ||
// Using a class works too. All that matters is that we implement | ||
// getItemAtIndex and getLength. | ||
this.infiniteItems = { | ||
numLoaded_: 0, | ||
toLoad_: 0, | ||
|
||
// Required. | ||
getItemAtIndex: function(index) { | ||
if (index > this.numLoaded_) { | ||
this.fetchMoreItems_(index); | ||
return null; | ||
} | ||
|
||
return index; | ||
}, | ||
|
||
// Required. | ||
// For infinite scroll behavior, we always return a slightly higher | ||
// number than the previously loaded items. | ||
getLength: function() { | ||
return this.numLoaded_ + 5; | ||
}, | ||
|
||
fetchMoreItems_: function(index) { | ||
// For demo purposes, we simulate loading more items with a timed | ||
// promise. In real code, this function would likely contain an | ||
// $http request. | ||
|
||
if (this.toLoad_ < index) { | ||
this.toLoad_ += 20; | ||
$timeout(angular.noop, 300).then(angular.bind(this, function() { | ||
this.numLoaded_ = this.toLoad_; | ||
})); | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#vertical-container { | ||
height: 292px; | ||
width: 400px; | ||
} | ||
|
||
.repeated-item { | ||
border-bottom: 1px solid #ddd; | ||
box-sizing: border-box; | ||
height: 40px; | ||
padding-top: 10px; | ||
} | ||
|
||
md-content { | ||
margin: 16px; | ||
} | ||
|
||
md-virtual-repeat-container { | ||
border: solid 1px grey; | ||
} | ||
|
||
.md-virtual-repeat-container .md-virtual-repeat-offsetter { | ||
padding-left: 16px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters