{"action":"created","issue":{"url":"https://api.github.com/repos/Polymer/polymer/issues/2677","labels_url":"https://api.github.com/repos/Polymer/polymer/issues/2677/labels{/name}","comments_url":"https://api.github.com/repos/Polymer/polymer/issues/2677/comments","events_url":"https://api.github.com/repos/Polymer/polymer/issues/2677/events","html_url":"https://github.com/Polymer/polymer/pull/2677","id":114932005,"number":2677,"title":"[API Proposal] Property Validations","user":{"login":"BLamy","id":324928,"avatar_url":"https://avatars.githubusercontent.com/u/324928?v=3","gravatar_id":"","url":"https://api.github.com/users/BLamy","html_url":"https://github.com/BLamy","followers_url":"https://api.github.com/users/BLamy/followers","following_url":"https://api.github.com/users/BLamy/following{/other_user}","gists_url":"https://api.github.com/users/BLamy/gists{/gist_id}","starred_url":"https://api.github.com/users/BLamy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BLamy/subscriptions","organizations_url":"https://api.github.com/users/BLamy/orgs","repos_url":"https://api.github.com/users/BLamy/repos","events_url":"https://api.github.com/users/BLamy/events{/privacy}","received_events_url":"https://api.github.com/users/BLamy/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Polymer/polymer/labels/cla:%20yes","name":"cla: yes","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-11-03T23:13:02Z","updated_at":"2015-11-25T19:22:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Polymer/polymer/pulls/2677","html_url":"https://github.com/Polymer/polymer/pull/2677","diff_url":"https://github.com/Polymer/polymer/pull/2677.diff","patch_url":"https://github.com/Polymer/polymer/pull/2677.patch"},"body":"Many web-components expose an external API. Configuring your element's attributes incorrectly typically results in your web component not working (usually a white screen of death). This can be relatively hard to debug if documentation is lacking. This PR proposes an API enhancement for supporting data validations in polymer. The goal is to be able to catch errors sooner and make for easier to debug applications  (Can provide strong static analysis of when using attributes improperly in HTML). This is done by adding your data validations directly in the properties info, which gives you one centralized place to look (other then docs) to figure out the required structure for a property.\r\n\r\n\r\nThis solution adds only about 50-75 lines to polymer and maintains backwards compatibility given that it is just progressive enhancement for your properties. \r\n\r\nData validations are added via `rules` and applied directly inside of the property's definition.\r\n```\r\nPolymer({\r\n      is:'x-foo',\r\n      rules: {\r\n        maxLength: function(val, arg) {\r\n          return (val.length <= arg);\r\n        },\r\n        minLength: function(val, arg) {\r\n          return (val.length >= arg);\r\n        }\r\n      },\r\n      properties: {\r\n        name: {\r\n          type: String,\r\n          maxLength: 5,\r\n          minLength: 3,\r\n          notify: true\r\n        }\r\n      }\r\n});\r\n```\r\n\r\nI'm no @robdodson but I attempted to create some videos explaining basic use cases. \r\n\r\n# Basic string rules \r\n[![Basic string rules ](http://img.youtube.com/vi/9hEoSML4lPA/0.jpg)](http://www.youtube.com/watch?v=9hEoSML4lPA)\r\n\r\n# Using behaviors and external libraries\r\n[![Using behaviors and external libraries ](http://img.youtube.com/vi/hKKwdzEREBA/0.jpg)](http://www.youtube.com/watch?v=hKKwdzEREBA)\r\n\r\n\r\n# Enum use case\r\n[![Enum use case ](http://img.youtube.com/vi/dBjcpvLZjj8/0.jpg)](http://www.youtube.com/watch?v=dBjcpvLZjj8)\r\n\r\n# property-name-invalid Notification \r\n[![property-name-invalid Notification  ](http://img.youtube.com/vi/GgahM8FEKrY/0.jpg)](http://www.youtube.com/watch?v=GgahM8FEKrY)\r\n"},"comment":{"url":"https://api.github.com/repos/Polymer/polymer/issues/comments/159706481","html_url":"https://github.com/Polymer/polymer/pull/2677#issuecomment-159706481","issue_url":"https://api.github.com/repos/Polymer/polymer/issues/2677","id":159706481,"user":{"login":"zoechi","id":405837,"avatar_url":"https://avatars.githubusercontent.com/u/405837?v=3","gravatar_id":"","url":"https://api.github.com/users/zoechi","html_url":"https://github.com/zoechi","followers_url":"https://api.github.com/users/zoechi/followers","following_url":"https://api.github.com/users/zoechi/following{/other_user}","gists_url":"https://api.github.com/users/zoechi/gists{/gist_id}","starred_url":"https://api.github.com/users/zoechi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoechi/subscriptions","organizations_url":"https://api.github.com/users/zoechi/orgs","repos_url":"https://api.github.com/users/zoechi/repos","events_url":"https://api.github.com/users/zoechi/events{/privacy}","received_events_url":"https://api.github.com/users/zoechi/received_events","type":"User","site_admin":false},"created_at":"2015-11-25T19:22:28Z","updated_at":"2015-11-25T19:22:28Z","body":"@blamy I don't see how to interpret it this way. He mentioned behavior and I assume he means something like iron-behaviors"}}