{"action":"created","comment":{"url":"https://api.github.com/repos/mother/oio/pulls/comments/89448126","pull_request_review_id":9992986,"id":89448126,"diff_hunk":"@@ -0,0 +1,184 @@\n+import React, { Component } from 'react'\n+import dot from 'dot-object'\n+\n+export default class Form extends Component {\n+   static propTypes = {\n+      children: React.PropTypes.node,\n+      onError: React.PropTypes.func,\n+      onSubmit: React.PropTypes.func\n+   }\n+\n+   constructor(props) {\n+      super(props)\n+\n+      this.handleSubmit = this.handleSubmit.bind(this)\n+\n+      this.initialValuesLoaded = false\n+\n+      // Setup state\n+      this.state = {}\n+      props.children.forEach((child) => {\n+         if (this.childIsRelevant(child)) {\n+            this.state[child.props.name] = {\n+               value: '',\n+               meta: {}\n+            }\n+         }\n+      })\n+   }\n+\n+   componentWillReceiveProps(props) {\n+      let initialValues = props.initialValues\n+\n+      if (initialValues && !this.initialValuesLoaded) {\n+         const newState = {}\n+\n+         initialValues = dot.dot(initialValues)\n+\n+         props.children.forEach((child) => {\n+            if (this.childIsRelevant(child)) {\n+               const value = initialValues\n+                  ? initialValues[child.props.name] || ''\n+                  : ''\n+               newState[child.props.name] = {\n+                  value,\n+                  meta: {\n+                     touched: false,\n+                     error: this.checkError(child, value, props)\n+                  }\n+               }\n+            }\n+         })\n+\n+         this.initialValuesLoaded = true\n+         this.setState(newState)\n+      }\n+   }\n+\n+   getTestFromString(str) {\n+      switch (str) {\n+         case 'required':\n+            return value => !!value\n+         case 'email':\n+            return (value) => {\n+               const regex = /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/ // eslint-disable-line\n+               return regex.test(value)\n+            }\n+         default:\n+            break\n+      }\n+   }\n+\n+   checkError(child, initialValue, initialProps) {\n+      const value = initialValue && typeof initialValue === 'string'\n+         ? initialValue\n+         : (this.state[child.props.name] && this.state[child.props.name].value) || ''\n+      const props = initialProps || this.props\n+\n+      const validations = props.validations && props.validations[child.props.name]\n+      if (!validations) return ''\n+\n+      for (let i = 0; i < validations.length; i += 1) {\n+         const validation = validations[i]\n+         const test = typeof validation.test === 'string'\n+            ? this.getTestFromString(validation.test)\n+            : validation.test\n+         if (!test(value)) {\n+            return validation.message\n+         }\n+      }\n+\n+      return ''\n+   }\n+\n+   childIsRelevant(child) {\n+      const types = ['input', 'textarea']\n+      return types.indexOf(child.type.type) !== -1","path":"src/components/Form/index.js","position":96,"original_position":96,"commit_id":"040892b571cf6b448289ac93c39566bf5de136ac","original_commit_id":"040892b571cf6b448289ac93c39566bf5de136ac","user":{"login":"asabhaney","id":324828,"avatar_url":"https://avatars.githubusercontent.com/u/324828?v=3","gravatar_id":"","url":"https://api.github.com/users/asabhaney","html_url":"https://github.com/asabhaney","followers_url":"https://api.github.com/users/asabhaney/followers","following_url":"https://api.github.com/users/asabhaney/following{/other_user}","gists_url":"https://api.github.com/users/asabhaney/gists{/gist_id}","starred_url":"https://api.github.com/users/asabhaney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asabhaney/subscriptions","organizations_url":"https://api.github.com/users/asabhaney/orgs","repos_url":"https://api.github.com/users/asabhaney/repos","events_url":"https://api.github.com/users/asabhaney/events{/privacy}","received_events_url":"https://api.github.com/users/asabhaney/received_events","type":"User","site_admin":false},"body":"I think you can use [includes](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) now. Life is much better in the ES6 world...","created_at":"2016-11-24T07:54:10Z","updated_at":"2016-11-24T07:54:10Z","html_url":"https://github.com/mother/oio/pull/15#discussion_r89448126","pull_request_url":"https://api.github.com/repos/mother/oio/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/mother/oio/pulls/comments/89448126"},"html":{"href":"https://github.com/mother/oio/pull/15#discussion_r89448126"},"pull_request":{"href":"https://api.github.com/repos/mother/oio/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/mother/oio/pulls/15","id":93643165,"html_url":"https://github.com/mother/oio/pull/15","diff_url":"https://github.com/mother/oio/pull/15.diff","patch_url":"https://github.com/mother/oio/pull/15.patch","issue_url":"https://api.github.com/repos/mother/oio/issues/15","number":15,"state":"open","locked":false,"title":"Forms","user":{"login":"jaredreich","id":8563847,"avatar_url":"https://avatars.githubusercontent.com/u/8563847?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredreich","html_url":"https://github.com/jaredreich","followers_url":"https://api.github.com/users/jaredreich/followers","following_url":"https://api.github.com/users/jaredreich/following{/other_user}","gists_url":"https://api.github.com/users/jaredreich/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredreich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredreich/subscriptions","organizations_url":"https://api.github.com/users/jaredreich/orgs","repos_url":"https://api.github.com/users/jaredreich/repos","events_url":"https://api.github.com/users/jaredreich/events{/privacy}","received_events_url":"https://api.github.com/users/jaredreich/received_events","type":"User","site_admin":false},"body":"OIO component to replace redux-form.\r\n\r\nFeatures:\r\n- [x] Form data submission with onSubmit\r\n- [x] Allow children components (Input, Textarea)\r\n- [x] Validation\r\n- [x] Allow form values with dot notation (\"name.first\") 10c7a12\r\n- [x] Allow custom shortcut validator tests (required, email) 040892b\r\n- [x] Allow for multiple validations on one key 040892b\r\n\r\nIssues:\r\n- [ ] Error checking not working when entire text is deleted (zero length input) when input is expecting a value length","created_at":"2016-11-14T20:37:21Z","updated_at":"2016-11-24T07:54:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a414c15166122606208e3ef490695c84bca1b45","assignee":{"login":"asabhaney","id":324828,"avatar_url":"https://avatars.githubusercontent.com/u/324828?v=3","gravatar_id":"","url":"https://api.github.com/users/asabhaney","html_url":"https://github.com/asabhaney","followers_url":"https://api.github.com/users/asabhaney/followers","following_url":"https://api.github.com/users/asabhaney/following{/other_user}","gists_url":"https://api.github.com/users/asabhaney/gists{/gist_id}","starred_url":"https://api.github.com/users/asabhaney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asabhaney/subscriptions","organizations_url":"https://api.github.com/users/asabhaney/orgs","repos_url":"https://api.github.com/users/asabhaney/repos","events_url":"https://api.github.com/users/asabhaney/events{/privacy}","received_events_url":"https://api.github.com/users/asabhaney/received_events","type":"User","site_admin":false},"assignees":[{"login":"asabhaney","id":324828,"avatar_url":"https://avatars.githubusercontent.com/u/324828?v=3","gravatar_id":"","url":"https://api.github.com/users/asabhaney","html_url":"https://github.com/asabhaney","followers_url":"https://api.github.com/users/asabhaney/followers","following_url":"https://api.github.com/users/asabhaney/following{/other_user}","gists_url":"https://api.github.com/users/asabhaney/gists{/gist_id}","starred_url":"https://api.github.com/users/asabhaney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asabhaney/subscriptions","organizations_url":"https://api.github.com/users/asabhaney/orgs","repos_url":"https://api.github.com/users/asabhaney/repos","events_url":"https://api.github.com/users/asabhaney/events{/privacy}","received_events_url":"https://api.github.com/users/asabhaney/received_events","type":"User","site_admin":false},{"login":"stevenyuen","id":326842,"avatar_url":"https://avatars.githubusercontent.com/u/326842?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenyuen","html_url":"https://github.com/stevenyuen","followers_url":"https://api.github.com/users/stevenyuen/followers","following_url":"https://api.github.com/users/stevenyuen/following{/other_user}","gists_url":"https://api.github.com/users/stevenyuen/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenyuen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenyuen/subscriptions","organizations_url":"https://api.github.com/users/stevenyuen/orgs","repos_url":"https://api.github.com/users/stevenyuen/repos","events_url":"https://api.github.com/users/stevenyuen/events{/privacy}","received_events_url":"https://api.github.com/users/stevenyuen/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/mother/oio/pulls/15/commits","review_comments_url":"https://api.github.com/repos/mother/oio/pulls/15/comments","review_comment_url":"https://api.github.com/repos/mother/oio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mother/oio/issues/15/comments","statuses_url":"https://api.github.com/repos/mother/oio/statuses/040892b571cf6b448289ac93c39566bf5de136ac","head":{"label":"mother:forms","ref":"forms","sha":"040892b571cf6b448289ac93c39566bf5de136ac","user":{"login":"mother","id":21103311,"avatar_url":"https://avatars.githubusercontent.com/u/21103311?v=3","gravatar_id":"","url":"https://api.github.com/users/mother","html_url":"https://github.com/mother","followers_url":"https://api.github.com/users/mother/followers","following_url":"https://api.github.com/users/mother/following{/other_user}","gists_url":"https://api.github.com/users/mother/gists{/gist_id}","starred_url":"https://api.github.com/users/mother/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mother/subscriptions","organizations_url":"https://api.github.com/users/mother/orgs","repos_url":"https://api.github.com/users/mother/repos","events_url":"https://api.github.com/users/mother/events{/privacy}","received_events_url":"https://api.github.com/users/mother/received_events","type":"Organization","site_admin":false},"repo":{"id":68413022,"name":"oio","full_name":"mother/oio","owner":{"login":"mother","id":21103311,"avatar_url":"https://avatars.githubusercontent.com/u/21103311?v=3","gravatar_id":"","url":"https://api.github.com/users/mother","html_url":"https://github.com/mother","followers_url":"https://api.github.com/users/mother/followers","following_url":"https://api.github.com/users/mother/following{/other_user}","gists_url":"https://api.github.com/users/mother/gists{/gist_id}","starred_url":"https://api.github.com/users/mother/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mother/subscriptions","organizations_url":"https://api.github.com/users/mother/orgs","repos_url":"https://api.github.com/users/mother/repos","events_url":"https://api.github.com/users/mother/events{/privacy}","received_events_url":"https://api.github.com/users/mother/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mother/oio","description":"A UI component kit for React","fork":false,"url":"https://api.github.com/repos/mother/oio","forks_url":"https://api.github.com/repos/mother/oio/forks","keys_url":"https://api.github.com/repos/mother/oio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mother/oio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mother/oio/teams","hooks_url":"https://api.github.com/repos/mother/oio/hooks","issue_events_url":"https://api.github.com/repos/mother/oio/issues/events{/number}","events_url":"https://api.github.com/repos/mother/oio/events","assignees_url":"https://api.github.com/repos/mother/oio/assignees{/user}","branches_url":"https://api.github.com/repos/mother/oio/branches{/branch}","tags_url":"https://api.github.com/repos/mother/oio/tags","blobs_url":"https://api.github.com/repos/mother/oio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mother/oio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mother/oio/git/refs{/sha}","trees_url":"https://api.github.com/repos/mother/oio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mother/oio/statuses/{sha}","languages_url":"https://api.github.com/repos/mother/oio/languages","stargazers_url":"https://api.github.com/repos/mother/oio/stargazers","contributors_url":"https://api.github.com/repos/mother/oio/contributors","subscribers_url":"https://api.github.com/repos/mother/oio/subscribers","subscription_url":"https://api.github.com/repos/mother/oio/subscription","commits_url":"https://api.github.com/repos/mother/oio/commits{/sha}","git_commits_url":"https://api.github.com/repos/mother/oio/git/commits{/sha}","comments_url":"https://api.github.com/repos/mother/oio/comments{/number}","issue_comment_url":"https://api.github.com/repos/mother/oio/issues/comments{/number}","contents_url":"https://api.github.com/repos/mother/oio/contents/{+path}","compare_url":"https://api.github.com/repos/mother/oio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mother/oio/merges","archive_url":"https://api.github.com/repos/mother/oio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mother/oio/downloads","issues_url":"https://api.github.com/repos/mother/oio/issues{/number}","pulls_url":"https://api.github.com/repos/mother/oio/pulls{/number}","milestones_url":"https://api.github.com/repos/mother/oio/milestones{/number}","notifications_url":"https://api.github.com/repos/mother/oio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mother/oio/labels{/name}","releases_url":"https://api.github.com/repos/mother/oio/releases{/id}","deployments_url":"https://api.github.com/repos/mother/oio/deployments","created_at":"2016-09-16T20:36:55Z","updated_at":"2016-10-25T07:07:34Z","pushed_at":"2016-11-23T22:42:23Z","git_url":"git://github.com/mother/oio.git","ssh_url":"git@github.com:mother/oio.git","clone_url":"https://github.com/mother/oio.git","svn_url":"https://github.com/mother/oio","homepage":null,"size":929,"stargazers_count":3,"watchers_count":3,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":3,"default_branch":"master"}},"base":{"label":"mother:master","ref":"master","sha":"fad0b203db858bb878a587644a23fee3393ca762","user":{"login":"mother","id":21103311,"avatar_url":"https://avatars.githubusercontent.com/u/21103311?v=3","gravatar_id":"","url":"https://api.github.com/users/mother","html_url":"https://github.com/mother","followers_url":"https://api.github.com/users/mother/followers","following_url":"https://api.github.com/users/mother/following{/other_user}","gists_url":"https://api.github.com/users/mother/gists{/gist_id}","starred_url":"https://api.github.com/users/mother/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mother/subscriptions","organizations_url":"https://api.github.com/users/mother/orgs","repos_url":"https://api.github.com/users/mother/repos","events_url":"https://api.github.com/users/mother/events{/privacy}","received_events_url":"https://api.github.com/users/mother/received_events","type":"Organization","site_admin":false},"repo":{"id":68413022,"name":"oio","full_name":"mother/oio","owner":{"login":"mother","id":21103311,"avatar_url":"https://avatars.githubusercontent.com/u/21103311?v=3","gravatar_id":"","url":"https://api.github.com/users/mother","html_url":"https://github.com/mother","followers_url":"https://api.github.com/users/mother/followers","following_url":"https://api.github.com/users/mother/following{/other_user}","gists_url":"https://api.github.com/users/mother/gists{/gist_id}","starred_url":"https://api.github.com/users/mother/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mother/subscriptions","organizations_url":"https://api.github.com/users/mother/orgs","repos_url":"https://api.github.com/users/mother/repos","events_url":"https://api.github.com/users/mother/events{/privacy}","received_events_url":"https://api.github.com/users/mother/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mother/oio","description":"A UI component kit for React","fork":false,"url":"https://api.github.com/repos/mother/oio","forks_url":"https://api.github.com/repos/mother/oio/forks","keys_url":"https://api.github.com/repos/mother/oio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mother/oio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mother/oio/teams","hooks_url":"https://api.github.com/repos/mother/oio/hooks","issue_events_url":"https://api.github.com/repos/mother/oio/issues/events{/number}","events_url":"https://api.github.com/repos/mother/oio/events","assignees_url":"https://api.github.com/repos/mother/oio/assignees{/user}","branches_url":"https://api.github.com/repos/mother/oio/branches{/branch}","tags_url":"https://api.github.com/repos/mother/oio/tags","blobs_url":"https://api.github.com/repos/mother/oio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mother/oio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mother/oio/git/refs{/sha}","trees_url":"https://api.github.com/repos/mother/oio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mother/oio/statuses/{sha}","languages_url":"https://api.github.com/repos/mother/oio/languages","stargazers_url":"https://api.github.com/repos/mother/oio/stargazers","contributors_url":"https://api.github.com/repos/mother/oio/contributors","subscribers_url":"https://api.github.com/repos/mother/oio/subscribers","subscription_url":"https://api.github.com/repos/mother/oio/subscription","commits_url":"https://api.github.com/repos/mother/oio/commits{/sha}","git_commits_url":"https://api.github.com/repos/mother/oio/git/commits{/sha}","comments_url":"https://api.github.com/repos/mother/oio/comments{/number}","issue_comment_url":"https://api.github.com/repos/mother/oio/issues/comments{/number}","contents_url":"https://api.github.com/repos/mother/oio/contents/{+path}","compare_url":"https://api.github.com/repos/mother/oio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mother/oio/merges","archive_url":"https://api.github.com/repos/mother/oio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mother/oio/downloads","issues_url":"https://api.github.com/repos/mother/oio/issues{/number}","pulls_url":"https://api.github.com/repos/mother/oio/pulls{/number}","milestones_url":"https://api.github.com/repos/mother/oio/milestones{/number}","notifications_url":"https://api.github.com/repos/mother/oio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mother/oio/labels{/name}","releases_url":"https://api.github.com/repos/mother/oio/releases{/id}","deployments_url":"https://api.github.com/repos/mother/oio/deployments","created_at":"2016-09-16T20:36:55Z","updated_at":"2016-10-25T07:07:34Z","pushed_at":"2016-11-23T22:42:23Z","git_url":"git://github.com/mother/oio.git","ssh_url":"git@github.com:mother/oio.git","clone_url":"https://github.com/mother/oio.git","svn_url":"https://github.com/mother/oio","homepage":null,"size":929,"stargazers_count":3,"watchers_count":3,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mother/oio/pulls/15"},"html":{"href":"https://github.com/mother/oio/pull/15"},"issue":{"href":"https://api.github.com/repos/mother/oio/issues/15"},"comments":{"href":"https://api.github.com/repos/mother/oio/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/mother/oio/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/mother/oio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mother/oio/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/mother/oio/statuses/040892b571cf6b448289ac93c39566bf5de136ac"}}}}
{"actor":{"display_login":"asabhaney"}}