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

Expose bare minimum to add property effects dynamically. #3456

Closed
kaste opened this issue Feb 23, 2016 · 4 comments
Closed

Expose bare minimum to add property effects dynamically. #3456

kaste opened this issue Feb 23, 2016 · 4 comments

Comments

@kaste
Copy link
Contributor

kaste commented Feb 23, 2016

As implemented #3460.

Following API:

  Polymer({
    is: 'x-custom-effect'
  });

  var el = document.createElement('x-custom-effect');

  var fx = el.addPropertyEffect('foo', function(path, value, old) {
    // path will be 'foo' or e.g. 'foo.splices' etc.
    // old value will only be avail if path is simple e.g. 'foo'
  });
  // do something
  // then later ... unregister
  el.removePropertyEffect(fx);
@dfreedm
Copy link
Member

dfreedm commented Feb 26, 2016

Can you describe what the use cases are for custom property effects with some examples?

@kaste
Copy link
Contributor Author

kaste commented Feb 26, 2016

Well I linked to numerous issues in the PR: #3420, #1796, #2131, #2638, #1778
Note: The PR just exposes the already implemented functionEffect. The only missing part is that Polymer does not define the equivalent path effect.

In a nutshell, this is just the straightforward code for what Polymer calls an annotationEffect:

// <x-foo prop="[[ bar ]]"></x-foo>
var el = document.createElement('x-foo');
this.addPropertyEffect('bar', function(path, value, oldValue) {
   el.prop = value;
});

And since a function effect is pretty low-level, you could rebuild all the effect kinds with it.

The problem with this PR is, adding elements gets damn easy, but removing them from the document requires that you also unregister all the custom effects, so you still have to keep track of that state.

The problem Polymer has, is that it somewhat fails in highly polymorphic situations: If you can't tell which elements/tags you will need to insert upfront, or if you just don't know which properties for example to bind to etc. Polymer also often forces you to use dom-repeats's or dom-if's although they don't perform that well and are highly opinionated in what they do and how they work and don't work.

@kaste
Copy link
Contributor Author

kaste commented Mar 30, 2016

I think this is a good use-case: #3547.

@tjsavage tjsavage added the 1.x label Sep 8, 2016
@TimvdLippe
Copy link
Contributor

This has been shipped in Polymer 2: https://www.polymer-project.org/2.0/docs/api/elements/Polymer.Element#method-addPropertyEffect Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants