Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Docs on creating custom filters #225

Closed
ebidel opened this Issue · 6 comments

4 participants

@ebidel
Owner

Tests: https://github.com/Polymer/polymer-expressions/blob/master/tests/tests.js#L96

PolymerExpressions.prototype.upObject = function(value) {
  return {
    toDOM: function(value) {
      var parts = [];
      console.log("I see value", value);
      for (var key in value) {

        parts.push(dict[key].toUpperCase())
      }
      return parts.join('; ');
    }
  };
};
@arv
Owner
arv commented

That is not entirely correct. The function should return the value. To do the inverse transformation add a toModel on the function:

PolymerExpressions.prototype.upObject = function(value) {
  var parts = [];
  console.log("I see value", value);
  for (var key in value) {
    parts.push(dict[key].toUpperCase())
  }
  return parts.join('; ');
};
PolymerExpressions.prototype.upObject.toModel = function(value) {
  ...
  return modelObject;
};
@ebidel
Owner

Thanks @arv. I hadn't dove into any of this yet. What about toDOM? Is that no longer required?

@arv
Owner
arv commented

toDom is implied now.

Before:

PolymerExpressions.foo = {
  toDom: funcA,
  toModel: funcB
};

now

PolymerExpressions.prototype.foo = funcA;
PolymerExpressions.prototype.foo.toModel = funcB;

@rafaelw To review that.

@sorvell
Owner

Custom filters are also now supported directly on the model, the custom element. The syntax is the same as @arv noted above. If the filter itself is a function then that function becomes the toDom value of the filter.

So, in some polymer-element...

<div>{{'thingy' | upperCaseFilter}}</div>

...
upperCaseFilter: function(value) {
  return value.toUpperCase();
}

// which is the same as
upperCaseFilter: {
  toDom: function(value) {
    return value.toUpperCase();
  }
  // add toModel when it makes sense...
}
@ebidel
Owner
@ebidel ebidel added the P0 label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.