-
Notifications
You must be signed in to change notification settings - Fork 24
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 events and mixins #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@platoscave In my mind the component should not know about the lazy stuff. It is only dumb UI. All we need to provide is utils and events so it can implemented by the end-developer easily.
Consequently, let's only keep a toggle
event on <paper-tree-node>
, that will bubble up to the top <paper-tree>
for listening purpose. So no CSS selectors specific to lazy loading, no embbeded svg.
Icon could be updated with something like:
<paper-tree on-toggle-children="toggleChildren"</paper-tree>
[...]
function toggleChildren(e) {
var node = e.detail;
node.set('data.icon', 'loading');
}
demo/lazyload-demo.html
Outdated
}); | ||
</script> | ||
</dom-module> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide something much more simpler and shorter ? This would act as a sample. It have to be understood in seconds. We only need to listen 'toggle' event and some lazy data fetcher (a few lines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a go at this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add it as a dom bind (instead of a component) in the demo page. and fix the former demos BTW 😅
loading.svg
Outdated
@@ -0,0 +1 @@ | |||
<svg id="loading" width='24px' height='24px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-default"><rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(0 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(30 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.08333333333333333s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(60 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.16666666666666666s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(90 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.25s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(120 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.3333333333333333s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(150 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.4166666666666667s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(180 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.5s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(210 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.5833333333333334s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(240 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.6666666666666666s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(270 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.75s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(300 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.8333333333333334s' repeatCount='indefinite'/></rect><rect x='46.5' y='40' width='7' height='20' rx='5' ry='5' fill='#00b2ff' transform='rotate(330 50 50) translate(0 -30)'> <animate attributeName='opacity' from='1' to='0' dur='1s' begin='0.9166666666666666s' repeatCount='indefinite'/></rect></svg> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained, lazyness is not part of the component. Consider remove this image.
paper-tree-node.html
Outdated
height:24px; | ||
margin-left:-24px; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Remove that block.
paper-tree-node.html
Outdated
* The `toggle-children` 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-children |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go for a toggle
event name.
paper-tree-node.html
Outdated
* Returns the necessary classes. | ||
* | ||
* @param {object} change An object containing the property that changed and its value. | ||
* @return {string} The class name indicating whether the node is open or closed | ||
*/ | ||
_computeClass: function(change) { | ||
if(change && change.base && change.base.loading) return 'node-preicon loading'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this also.
paper-tree-node.html
Outdated
@@ -218,6 +242,7 @@ | |||
*/ | |||
toggleChildren: function() { | |||
this.set("data.open", !this.data.open && this.data.children && this.data.children.length); | |||
this.fire("toggle-children", this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.fire('toggle', this);
@vpusher While I agree with your philosophy, I don't necessarily agree that adding a loading state detracts from "dumbness". Lazy loading is especially important in enterprise applications where we're dealing with large amounts of data which we don't want to download all at once. This is where paper-tree will come into its own. It makes sense to provide minimal support for this out-of-the-box. |
I know how important it is to lazy load data, and how much you need it in some case. The thing is some will want to update the pre-icon, the others will want to update the icon and perhaps some others will want a loading text message (or both, or the three). That is to say the way the loading feedback is rendered is under the end developer responsibility. I don't want to take any opinion on this. This is a view that is bound to a model and it provides some hooks/events to implement you own logic. To resume, to solve your issue the component needs the followings openings/hooks: [x] know when children are toggled: a |
@vpusher The lazyload-demo is now much simpler and works fine, all except for applying the 'loading' class to the pre-icon span. The 'loading' class needs to be applied shortly after the node is created due to a data update. These spans are really hard to find. I thought about searching the dom tree but this is generally discouraged because "It requires the consumer to be aware about element's internals. Web component should only be used with properties/attributes and events". What would be a good way to get access the pre-icon span so that we can modify it's class? |
@platoscave what about my last commit ? does it fit your needs ? |
We have to add I'm also testing
The only problem here is the issue which I mentioned earlier: iron-icon Note: I had to add How does one go about running the demo's, given that there is no bower-components context? |
@platoscave do you run it with |
In my opinion the solution here is overly complicated. You can lazy render simply by using dom-if in a template on children. If a node isn't visible it isn't rendered (yet). |
@benbenbenbenbenben here we are mostly dealing with customizing the UI through openings/hooks such as events and mixins (to fit the use case of @platoscave). Data lazy loading is totally in charged of the end developer. That's the first point. The second point is about lazy render the tree, and that is the purpose of your PR. Tank you for that, I will consider it, merge it and then release a new version of the component with those 2 enhancements (PRs). |
@platoscave I am merging this one. Most of your use cases are covered now, and the current implementation seems generic enough to me. Please address a new PR for the icon |
@vpusher okay thanks for this |
@platoscave Released in v1.0.3 |
This branch contains features that facilitate lazy loading
Including in paper-tree-node:
toggle-children
event fired from toggleChildren.node-preicon.loading:before
src$="[[data.src]]"
to the iron-icon (not related to lazy loading)white-space: nowrap;
to node-container (not related to lazy loading)New files:
Chris