Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy loading through dom-if #4

Merged
merged 3 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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