Skip to content

Commit

Permalink
Merge pull request #4 from benbenbenbenbenben/master
Browse files Browse the repository at this point in the history
lazy loading through dom-if
  • Loading branch information
vpusher committed Mar 8, 2017
2 parents dbe1818 + 8758294 commit 3c4c7ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
10 changes: 6 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ <h3>Lazy loading demo</h3>
template.onToggle = function(event) {
var target = event.detail;

!target.loaded && target.getChildren().forEach(function(child){
if (!target.loaded) {
target.loaded = true;
// Fetching children ...
this.fetchChildren(child);
}, this);
target.getChildren().forEach(function(child){
// Fetching children ...
this.fetchChildren(child);
}, this);
}
},

template.setLoadingState = function(node, enabled) {
Expand Down
10 changes: 6 additions & 4 deletions demo/lazyloading.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ <h2>Lazy loading paper-tree demo</h2>
template.onToggle = function(event) {
var target = event.detail;

!target.loaded && target.getChildren().forEach(function(child){
if (!target.loaded) {
target.loaded = true;
// Fetching children ...
this.fetchChildren(child);
}, this);
target.getChildren().forEach(function(child){
// Fetching children ...
this.fetchChildren(child);
}, this);
}
},

template.setLoadingState = function(node, enabled) {
Expand Down
19 changes: 10 additions & 9 deletions paper-tree-node.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@
</paper-menu-button>
</template>
</div>
<ul hidden$={{!data.open}}>
<template is="dom-repeat" items="{{data.children}}">
<li>
<paper-tree-node data="{{item}}" actions="{{actions}}"></paper-tree-node>
</li>
</template>
</ul>
<template is="dom-if" if="{{data.open}}">
<ul>
<template is="dom-repeat" items="{{data.children}}">
<li>
<paper-tree-node data="{{item}}" actions="{{actions}}"></paper-tree-node>
</li>
</template>
</ul>
</template>
</div>
</template>

Expand Down Expand Up @@ -185,7 +187,6 @@

/**
* The `toggle` event is fired whenever a tree node is expanded or collapsed.
* This event can be used by the host to lazy load grandchildren.
*
* @event toggle
*/
Expand Down Expand Up @@ -242,7 +243,7 @@
*/
toggleChildren: function() {
this.set("data.open", !this.data.open && this.data.children && this.data.children.length);
this.fire("toggle", this);
setTimeout(this.fire.bind(this, "toggle", this));
}

});
Expand Down

0 comments on commit 3c4c7ec

Please sign in to comment.