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

Fix warnings found by the new linter #114

Closed
wants to merge 5 commits into from
Closed

Conversation

rictic
Copy link
Contributor

@rictic rictic commented Mar 18, 2017

Note, this PR is a work in progress. It definitely isn't ready to merge until Polymer/polymer-analyzer#543 has landed and the new imports in shop-app are rel="lazy-import"

@@ -18,11 +18,25 @@
<link rel="import" href="../bower_components/iron-media-query/iron-media-query.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paper-icon-button is lazily imported by lazy-resources.html and should not be imported here.

This is also the case for the other added imports in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here.

Hm, for cases where one element uses another one but depends on its container doing a lazy import of it... that's a bit tricky. How do you capture that pattern declaratively?

The option I went with here was to add a lazy import of lazy-resources.html to each of the pages, as they can be sure that those resources will eventually be imported.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rictic this should be changed to a lazy import I guess

@@ -72,4 +72,11 @@

</style>
</template>
<script>
// TODO(rictic): how does this work with just a dom-module? Is that kosher?
// https://github.com/Polymer/polymer-analyzer/issues/573
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replied there with a proposal.

<link rel="import" href="shop-list.html">
<link rel="import" href="shop-detail.html">
<link rel="import" href="shop-cart.html">
<link rel="import" href="shop-checkout.html">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have voiced my opinion in the #tools channel and in direct messages with you on Slack, that I really dislike this pattern. It essentially requires users to 1. specify the routes in the selector, 2. specify the fragments and 3. specify the lazy-imports. This is not DRY and is very error-prone for the users.

Point 2 of the above list can of course be derived from point 3, but why can't these both be derived from point 1? The problem specifically in the shop app is that it relies on Polymer.Base.importHref which is extremely hard to analyze statically. Therefore I would like to request a solution that is statically analyzable, which is DRY (in the sense that it only requires users to specify the routes in the selector) and user-friendly.

Any sort of hint or pattern for the analyzer to conclude the different fragments that are lazy-loaded would be sufficient, to which it can combine the final document locations together with the routes. I am not aware of any clear solution, which would work for all users, given that the shop lazy-loading pattern is very specific to this application. A lot of other users are probably relying on a different mechanism, but at the moment I do not know all of the patterns that are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By fragments do you mean the DOM to display for each possible choice in iron-pages?

IMO the routes, the per-page DOM, and the urls are three separate concerns, so I'm not concerned that all three need to be specified, but I am a little uncomfortable with how they're specified in such different places such that it's easy for them to get out of sync.

IMO your iron-lazy-pages element goes in the right direction, by specifying the per-page dom in the same place that you specify the url that needs to be imported to render that page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By fragments do you mean the DOM to display for each possible choice in iron-pages?

No I meant the fragments as specified in the polymer.json

Yes I agree that they are separate concerns, which should be specified, but if these are in different places people forget things. We have hit this exact problem multiple times, in which I built custom scripts to fix that. Yes these custom scripts do use iron-lazy-pages, since we are using them, but at least they give more security for us as application developers that stuff doesn't break when we deploy.

I feel that these custom scripts should be integrated somewhere, without too much hassle for the user. Moreover, the same mechanic can be used to analyze the lazy-fragments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Yeah, that seems very reasonable. Something like, for every fragment in fragments there should be a lazy import of it somewhere in the application?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I would like to have single point of truth. The fragments are related to how they are imported and in the shop application are directly retrieved from the name of the routes. Therefore, the names of the routes are the single point of truth imo and the other two can be derived from them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimvdLippe just pointed me here, I think making these lazy imports is exactly the right solution. Then we can work towards not requiring the to be also specified as fragments in polymer.json.

@frankiefu
Copy link
Member

Should this PR be on 2.0-preview branch (or 2.0-preview-class for Class-based syntax)? master is still for Polymer 1.x stuffs.

Found one maybe-legit bug where we were setting the name property instead of the name attribute in an iron-selector with attr-for-selected.

Found a few more places where there were missing imports.

And finally, found a few places where the analyzer or a lint rule got confused. Filed bugs or sent PRs for all those.
@rictic rictic changed the base branch from master to 2.0-preview-class May 11, 2017 04:15
@rictic rictic force-pushed the lint-clean branch 3 times, most recently from 58e24b1 to c0fa87f Compare May 11, 2017 04:43
@rictic
Copy link
Contributor Author

rictic commented May 11, 2017

Updated to point to 2.0-preview-class

@@ -18,11 +18,25 @@
<link rel="import" href="../bower_components/iron-media-query/iron-media-query.html">
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rictic this should be changed to a lazy import I guess

@@ -14,7 +14,7 @@
<link rel="import" href="shop-form-styles.html">

<dom-module id="shop-cart">

<link rel="lazy-import" href="lazy-resources.html" group="imported-by-app">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment, and maybe a todo to restructure lazy imports to be loaded more locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -19,7 +19,8 @@
"iron-pages": "polymerelements/iron-pages#2.0-preview",
"iron-selector": "polymerelements/iron-selector#2.0-preview",
"paper-icon-button": "polymerelements/paper-icon-button#2.0-preview",
"paper-spinner": "polymerelements/paper-spinner#2.0-preview"
"paper-spinner": "polymerelements/paper-spinner#2.0-preview",
"lazy-imports": "Polymer/lazy-imports#master"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2.0.0 has landed 🎉 Maybe rebasing this would be a good start 👍

@@ -281,7 +288,7 @@
attr-for-selected="name">
<dom-repeat items="[[categories]]" as="category" initial-count="4">
<template>
<shop-tab name="[[category.name]]">
<shop-tab name$="[[category.name]]">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: indent 2 spaces?

@@ -14,6 +14,7 @@
<link rel="import" href="shop-icons.html">
<link rel="import" href="shop-image.html">
<link rel="import" href="shop-select.html">
<link rel="import" href="shop-md-decorator.html">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be added as a lazy-import which won't actually require the fake elements to exist.

@@ -72,4 +72,10 @@

</style>
</template>
<script>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed for a style module?


<!--
This is lazy imported in shop-app so we can assume that it's lazy imported
here too. Maybe this should be loaded more locally though?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 For loading more locally

@keanulee
Copy link
Contributor

Stale PR. Please make a new one if necessary.

@keanulee keanulee closed this Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants