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

Add 2.x option to treat complex observers as they were in Polymer1 #5262

Closed
beckysiegel opened this issue Jun 18, 2018 · 4 comments · Fixed by #5339
Closed

Add 2.x option to treat complex observers as they were in Polymer1 #5262

beckysiegel opened this issue Jun 18, 2018 · 4 comments · Fixed by #5339

Comments

@beckysiegel
Copy link
Contributor

beckysiegel commented Jun 18, 2018

In order to smooth the upgrade process, add an option at the element level to not call observer/computed functions if any of the arguments is undefined.

Example:

properties: { foo: String, bar: String, baz: { type: String, computed: computedFn(foo, bar), }, usePolymer1StyleObserver: true, }, computedFn(foo, bar) { return foo + bar; }

@jsilvermist
Copy link

Why not just add at the beginning:

if (!foo || !bar) return;

Or

if (foo === undefined || bar === undefined) return;

@web-padawan
Copy link
Contributor

You can also do it like this:

if (Array.from(arguments).some(arg => arg === undefined))

@TimvdLippe
Copy link
Contributor

I am inclined to agree with @jsilvermist and @web-padawan here. It should be quite straightforward to handle these cases. This also makes the logic more explicit. I would therefore be against adding such an option.

@beckysiegel
Copy link
Contributor Author

Sorry, I didn't illustrate the real problem very well. It's very clear in this case that you can add:
if (foo === undefined || bar === undefined) return;

However, I've worked on upgrading an app with many elements, and thousands of places where this can happen, many not as obvious as this. A few examples:

  • An property that has a default value set, but is also two way bound to its parent. It can be undefined when not expected
  • Computed values in templates

This issue is a huge pain point for large apps with many async properties. My goal is to make it easier to incrementally add the undefined checks as you are suggesting.

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 a pull request may close this issue.

4 participants