{"action":"created","comment":{"url":"https://api.github.com/repos/neoziro/recompact/pulls/comments/168947172","pull_request_review_id":97398965,"id":168947172,"diff_hunk":"@@ -0,0 +1,70 @@\n+import createHelper from './createHelper'\n+import callOrUse from './utils/callOrUse'\n+import updateProps from './utils/updateProps'\n+import mapValues from './utils/mapValues'\n+\n+/**\n+ * Passes state object properties and immutable updater functions in a form of\n+ * `(...payload: any[]) => Object` to the base component.\n+ *\n+ * Every state updater function accepts state, props and payload and must return\n+ * a new state or undefined. The new state is shallowly merged with the previous\n+ * state.\n+ *\n+ * @static\n+ * @category Higher-order-components\n+ * @param {Object|Function} initialState\n+ * @param {Object} stateUpdaters\n+ * @returns {HigherOrderComponent} A function that takes a component and returns a new component.\n+ * @example\n+ *\n+ * const Counter = withStateHandlers(\n+ *   ({ initialCounter = 0 }) => ({\n+ *     counter: initialCounter,\n+ *   }),\n+ *   {\n+ *     incrementOn: ({ counter }) => (value) => ({\n+ *       counter: counter + value,\n+ *     }),\n+ *     decrementOn: ({ counter }) => (value) => ({\n+ *       counter: counter - value,\n+ *     }),\n+ *     resetCounter: (_, { initialCounter = 0 }) => () => ({\n+ *       counter: initialCounter,\n+ *     }),\n+ *   }\n+ * )(\n+ *   ({ counter, incrementOn, decrementOn, resetCounter }) =>\n+ *     <div>\n+ *       <Button onClick={() => incrementOn(2)}>Inc</Button>\n+ *       <Button onClick={() => decrementOn(3)}>Dec</Button>\n+ *       <Button onClick={resetCounter}>Reset</Button>\n+ *     </div>\n+ * )\n+ */\n+const withStateHandlers = (initialState, stateUpdaters) =>\n+  updateProps(next => {\n+    let props\n+    let state\n+\n+    const handlers = mapValues(stateUpdaters, handler => (...args) => {\n+      state = { ...state, ...handler(state, props)(...args) }","path":"src/withStateHandlers.js","position":51,"original_position":51,"commit_id":"7976a18bccd5a57032f2ee687b7d258362450e0c","original_commit_id":"7976a18bccd5a57032f2ee687b7d258362450e0c","user":{"login":"matthieuprat","id":890117,"avatar_url":"https://avatars1.githubusercontent.com/u/890117?v=4","gravatar_id":"","url":"https://api.github.com/users/matthieuprat","html_url":"https://github.com/matthieuprat","followers_url":"https://api.github.com/users/matthieuprat/followers","following_url":"https://api.github.com/users/matthieuprat/following{/other_user}","gists_url":"https://api.github.com/users/matthieuprat/gists{/gist_id}","starred_url":"https://api.github.com/users/matthieuprat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthieuprat/subscriptions","organizations_url":"https://api.github.com/users/matthieuprat/orgs","repos_url":"https://api.github.com/users/matthieuprat/repos","events_url":"https://api.github.com/users/matthieuprat/events{/privacy}","received_events_url":"https://api.github.com/users/matthieuprat/received_events","type":"User","site_admin":false},"body":"Recompose calls `persist` on the first argument if it is a SyntheticEvent (acdlite/recompose#476). I think we want to go the same way. Would you be willing to address this?","created_at":"2018-02-18T10:31:29Z","updated_at":"2018-02-18T10:31:54Z","html_url":"https://github.com/neoziro/recompact/pull/96#discussion_r168947172","pull_request_url":"https://api.github.com/repos/neoziro/recompact/pulls/96","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/neoziro/recompact/pulls/comments/168947172"},"html":{"href":"https://github.com/neoziro/recompact/pull/96#discussion_r168947172"},"pull_request":{"href":"https://api.github.com/repos/neoziro/recompact/pulls/96"}}},"pull_request":{"url":"https://api.github.com/repos/neoziro/recompact/pulls/96","id":168483294,"html_url":"https://github.com/neoziro/recompact/pull/96","diff_url":"https://github.com/neoziro/recompact/pull/96.diff","patch_url":"https://github.com/neoziro/recompact/pull/96.patch","issue_url":"https://api.github.com/repos/neoziro/recompact/issues/96","number":96,"state":"open","locked":false,"title":"Add withStateHandlers()","user":{"login":"helixbass","id":440230,"avatar_url":"https://avatars2.githubusercontent.com/u/440230?v=4","gravatar_id":"","url":"https://api.github.com/users/helixbass","html_url":"https://github.com/helixbass","followers_url":"https://api.github.com/users/helixbass/followers","following_url":"https://api.github.com/users/helixbass/following{/other_user}","gists_url":"https://api.github.com/users/helixbass/gists{/gist_id}","starred_url":"https://api.github.com/users/helixbass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helixbass/subscriptions","organizations_url":"https://api.github.com/users/helixbass/orgs","repos_url":"https://api.github.com/users/helixbass/repos","events_url":"https://api.github.com/users/helixbass/events{/privacy}","received_events_url":"https://api.github.com/users/helixbass/received_events","type":"User","site_admin":false},"body":"Fixes #90 \r\n\r\nAdds support for `withStateHandlers()`\r\n\r\nI'm not highly familiar with `recompact` codebase but pieced this together by looking at implementations of `withState()`, `withHandlers()`, and `recompose`'s `withStateHandlers()` implementation (as well as corresponding tests)\r\n\r\nComparing to `recompose`'s tests:\r\n- Omitted `withStateHandlers initial state must be function or object or null or undefined`, which checks that mounting with `initialState` `1` throws an error (because it uses `.setState()`, which we don't here)\r\n- Omitted `withStateHandlers should persist events passed as argument`, since we're not using a `.setState()` callback there seems to be no need to persist events\r\n- Omitted `withStateHandlers does not rerender if state updater returns undefined` (and related following test), as well as the corresponding documentation \"Returning undefined does not cause a component rerender.\"\r\n  - If this behavior (of not rerendering) is desirable, it seems like perhaps it would be possible (though I'm not familiar with how `updateProps()` works) to do this by caching the last object passed to `next()` and then passing the cached object to `next()` if the handler (`handler(state, props)(...args)`) returns undefined?\r\n\r\nIncluded documentation in `withStateHandlers` module but didn't run eg `yarn run build`, please let me know if there are any scripts like that which I should run for the purposes of this PR, thanks","created_at":"2018-02-12T00:12:15Z","updated_at":"2018-02-18T10:31:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fc7632fa7296d1f4c0c565df1466e8c2dc4c9ea8","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/neoziro/recompact/pulls/96/commits","review_comments_url":"https://api.github.com/repos/neoziro/recompact/pulls/96/comments","review_comment_url":"https://api.github.com/repos/neoziro/recompact/pulls/comments{/number}","comments_url":"https://api.github.com/repos/neoziro/recompact/issues/96/comments","statuses_url":"https://api.github.com/repos/neoziro/recompact/statuses/7976a18bccd5a57032f2ee687b7d258362450e0c","head":{"label":"helixbass:with-state-handlers","ref":"with-state-handlers","sha":"7976a18bccd5a57032f2ee687b7d258362450e0c","user":{"login":"helixbass","id":440230,"avatar_url":"https://avatars2.githubusercontent.com/u/440230?v=4","gravatar_id":"","url":"https://api.github.com/users/helixbass","html_url":"https://github.com/helixbass","followers_url":"https://api.github.com/users/helixbass/followers","following_url":"https://api.github.com/users/helixbass/following{/other_user}","gists_url":"https://api.github.com/users/helixbass/gists{/gist_id}","starred_url":"https://api.github.com/users/helixbass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helixbass/subscriptions","organizations_url":"https://api.github.com/users/helixbass/orgs","repos_url":"https://api.github.com/users/helixbass/repos","events_url":"https://api.github.com/users/helixbass/events{/privacy}","received_events_url":"https://api.github.com/users/helixbass/received_events","type":"User","site_admin":false},"repo":{"id":120141062,"name":"recompact","full_name":"helixbass/recompact","owner":{"login":"helixbass","id":440230,"avatar_url":"https://avatars2.githubusercontent.com/u/440230?v=4","gravatar_id":"","url":"https://api.github.com/users/helixbass","html_url":"https://github.com/helixbass","followers_url":"https://api.github.com/users/helixbass/followers","following_url":"https://api.github.com/users/helixbass/following{/other_user}","gists_url":"https://api.github.com/users/helixbass/gists{/gist_id}","starred_url":"https://api.github.com/users/helixbass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/helixbass/subscriptions","organizations_url":"https://api.github.com/users/helixbass/orgs","repos_url":"https://api.github.com/users/helixbass/repos","events_url":"https://api.github.com/users/helixbass/events{/privacy}","received_events_url":"https://api.github.com/users/helixbass/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/helixbass/recompact","description":"⚛ A set of React higher-order components utilities. Drop-in replacement for recompose.","fork":true,"url":"https://api.github.com/repos/helixbass/recompact","forks_url":"https://api.github.com/repos/helixbass/recompact/forks","keys_url":"https://api.github.com/repos/helixbass/recompact/keys{/key_id}","collaborators_url":"https://api.github.com/repos/helixbass/recompact/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/helixbass/recompact/teams","hooks_url":"https://api.github.com/repos/helixbass/recompact/hooks","issue_events_url":"https://api.github.com/repos/helixbass/recompact/issues/events{/number}","events_url":"https://api.github.com/repos/helixbass/recompact/events","assignees_url":"https://api.github.com/repos/helixbass/recompact/assignees{/user}","branches_url":"https://api.github.com/repos/helixbass/recompact/branches{/branch}","tags_url":"https://api.github.com/repos/helixbass/recompact/tags","blobs_url":"https://api.github.com/repos/helixbass/recompact/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/helixbass/recompact/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/helixbass/recompact/git/refs{/sha}","trees_url":"https://api.github.com/repos/helixbass/recompact/git/trees{/sha}","statuses_url":"https://api.github.com/repos/helixbass/recompact/statuses/{sha}","languages_url":"https://api.github.com/repos/helixbass/recompact/languages","stargazers_url":"https://api.github.com/repos/helixbass/recompact/stargazers","contributors_url":"https://api.github.com/repos/helixbass/recompact/contributors","subscribers_url":"https://api.github.com/repos/helixbass/recompact/subscribers","subscription_url":"https://api.github.com/repos/helixbass/recompact/subscription","commits_url":"https://api.github.com/repos/helixbass/recompact/commits{/sha}","git_commits_url":"https://api.github.com/repos/helixbass/recompact/git/commits{/sha}","comments_url":"https://api.github.com/repos/helixbass/recompact/comments{/number}","issue_comment_url":"https://api.github.com/repos/helixbass/recompact/issues/comments{/number}","contents_url":"https://api.github.com/repos/helixbass/recompact/contents/{+path}","compare_url":"https://api.github.com/repos/helixbass/recompact/compare/{base}...{head}","merges_url":"https://api.github.com/repos/helixbass/recompact/merges","archive_url":"https://api.github.com/repos/helixbass/recompact/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/helixbass/recompact/downloads","issues_url":"https://api.github.com/repos/helixbass/recompact/issues{/number}","pulls_url":"https://api.github.com/repos/helixbass/recompact/pulls{/number}","milestones_url":"https://api.github.com/repos/helixbass/recompact/milestones{/number}","notifications_url":"https://api.github.com/repos/helixbass/recompact/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/helixbass/recompact/labels{/name}","releases_url":"https://api.github.com/repos/helixbass/recompact/releases{/id}","deployments_url":"https://api.github.com/repos/helixbass/recompact/deployments","created_at":"2018-02-04T00:05:06Z","updated_at":"2018-02-04T00:05:09Z","pushed_at":"2018-02-11T23:54:17Z","git_url":"git://github.com/helixbass/recompact.git","ssh_url":"git@github.com:helixbass/recompact.git","clone_url":"https://github.com/helixbass/recompact.git","svn_url":"https://github.com/helixbass/recompact","homepage":"https://neoziro.github.io/recompact/","size":867,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"neoziro:master","ref":"master","sha":"4de94afeeb0f42443b3f06461fc56e4ba0ab0208","user":{"login":"neoziro","id":266302,"avatar_url":"https://avatars2.githubusercontent.com/u/266302?v=4","gravatar_id":"","url":"https://api.github.com/users/neoziro","html_url":"https://github.com/neoziro","followers_url":"https://api.github.com/users/neoziro/followers","following_url":"https://api.github.com/users/neoziro/following{/other_user}","gists_url":"https://api.github.com/users/neoziro/gists{/gist_id}","starred_url":"https://api.github.com/users/neoziro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neoziro/subscriptions","organizations_url":"https://api.github.com/users/neoziro/orgs","repos_url":"https://api.github.com/users/neoziro/repos","events_url":"https://api.github.com/users/neoziro/events{/privacy}","received_events_url":"https://api.github.com/users/neoziro/received_events","type":"User","site_admin":false},"repo":{"id":73489298,"name":"recompact","full_name":"neoziro/recompact","owner":{"login":"neoziro","id":266302,"avatar_url":"https://avatars2.githubusercontent.com/u/266302?v=4","gravatar_id":"","url":"https://api.github.com/users/neoziro","html_url":"https://github.com/neoziro","followers_url":"https://api.github.com/users/neoziro/followers","following_url":"https://api.github.com/users/neoziro/following{/other_user}","gists_url":"https://api.github.com/users/neoziro/gists{/gist_id}","starred_url":"https://api.github.com/users/neoziro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neoziro/subscriptions","organizations_url":"https://api.github.com/users/neoziro/orgs","repos_url":"https://api.github.com/users/neoziro/repos","events_url":"https://api.github.com/users/neoziro/events{/privacy}","received_events_url":"https://api.github.com/users/neoziro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/neoziro/recompact","description":"⚛ A set of React higher-order components utilities. Drop-in replacement for recompose.","fork":false,"url":"https://api.github.com/repos/neoziro/recompact","forks_url":"https://api.github.com/repos/neoziro/recompact/forks","keys_url":"https://api.github.com/repos/neoziro/recompact/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neoziro/recompact/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neoziro/recompact/teams","hooks_url":"https://api.github.com/repos/neoziro/recompact/hooks","issue_events_url":"https://api.github.com/repos/neoziro/recompact/issues/events{/number}","events_url":"https://api.github.com/repos/neoziro/recompact/events","assignees_url":"https://api.github.com/repos/neoziro/recompact/assignees{/user}","branches_url":"https://api.github.com/repos/neoziro/recompact/branches{/branch}","tags_url":"https://api.github.com/repos/neoziro/recompact/tags","blobs_url":"https://api.github.com/repos/neoziro/recompact/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neoziro/recompact/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neoziro/recompact/git/refs{/sha}","trees_url":"https://api.github.com/repos/neoziro/recompact/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neoziro/recompact/statuses/{sha}","languages_url":"https://api.github.com/repos/neoziro/recompact/languages","stargazers_url":"https://api.github.com/repos/neoziro/recompact/stargazers","contributors_url":"https://api.github.com/repos/neoziro/recompact/contributors","subscribers_url":"https://api.github.com/repos/neoziro/recompact/subscribers","subscription_url":"https://api.github.com/repos/neoziro/recompact/subscription","commits_url":"https://api.github.com/repos/neoziro/recompact/commits{/sha}","git_commits_url":"https://api.github.com/repos/neoziro/recompact/git/commits{/sha}","comments_url":"https://api.github.com/repos/neoziro/recompact/comments{/number}","issue_comment_url":"https://api.github.com/repos/neoziro/recompact/issues/comments{/number}","contents_url":"https://api.github.com/repos/neoziro/recompact/contents/{+path}","compare_url":"https://api.github.com/repos/neoziro/recompact/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neoziro/recompact/merges","archive_url":"https://api.github.com/repos/neoziro/recompact/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neoziro/recompact/downloads","issues_url":"https://api.github.com/repos/neoziro/recompact/issues{/number}","pulls_url":"https://api.github.com/repos/neoziro/recompact/pulls{/number}","milestones_url":"https://api.github.com/repos/neoziro/recompact/milestones{/number}","notifications_url":"https://api.github.com/repos/neoziro/recompact/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neoziro/recompact/labels{/name}","releases_url":"https://api.github.com/repos/neoziro/recompact/releases{/id}","deployments_url":"https://api.github.com/repos/neoziro/recompact/deployments","created_at":"2016-11-11T15:34:24Z","updated_at":"2018-02-17T15:29:25Z","pushed_at":"2018-02-12T00:12:16Z","git_url":"git://github.com/neoziro/recompact.git","ssh_url":"git@github.com:neoziro/recompact.git","clone_url":"https://github.com/neoziro/recompact.git","svn_url":"https://github.com/neoziro/recompact","homepage":"https://neoziro.github.io/recompact/","size":927,"stargazers_count":223,"watchers_count":223,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":15,"mirror_url":null,"archived":false,"open_issues_count":9,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":15,"open_issues":9,"watchers":223,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/neoziro/recompact/pulls/96"},"html":{"href":"https://github.com/neoziro/recompact/pull/96"},"issue":{"href":"https://api.github.com/repos/neoziro/recompact/issues/96"},"comments":{"href":"https://api.github.com/repos/neoziro/recompact/issues/96/comments"},"review_comments":{"href":"https://api.github.com/repos/neoziro/recompact/pulls/96/comments"},"review_comment":{"href":"https://api.github.com/repos/neoziro/recompact/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/neoziro/recompact/pulls/96/commits"},"statuses":{"href":"https://api.github.com/repos/neoziro/recompact/statuses/7976a18bccd5a57032f2ee687b7d258362450e0c"}},"author_association":"NONE"}}
{"actor":{"display_login":"matthieuprat"}}