{"action":"created","comment":{"url":"https://api.github.com/repos/marmelab/react-admin/pulls/comments/243279325","pull_request_review_id":186999470,"id":243279325,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MzI3OTMyNQ==","diff_hunk":"@@ -60,40 +57,43 @@ const addRecords = addRecordsFactory(getFetchedAt);\n const initialState = {};\n Object.defineProperty(initialState, 'fetchedAt', { value: {} }); // non enumerable by default\n \n-export default (previousState = initialState, { type, payload, meta }) => {\n-    if (type === CRUD_UPDATE_OPTIMISTIC) {\n-        const updatedRecord = { ...previousState[payload.id], ...payload.data };\n-        return addRecords([updatedRecord], previousState);\n-    }\n-    if (type === CRUD_UPDATE_MANY_OPTIMISTIC) {\n-        const updatedRecords = payload.ids\n-            .reduce((records, id) => records.concat(previousState[id]), [])\n-            .map(record => ({ ...record, ...payload.data }));\n-        return addRecords(updatedRecords, previousState);\n-    }\n-    if (type === CRUD_DELETE_OPTIMISTIC) {\n-        const { [payload.id]: removed, ...newState } = previousState;\n+export default (previousState = initialState, { payload, meta }) => {\n+    if (meta && meta.optimistic) {\n+        if (meta.fetch === UPDATE) {\n+            const updatedRecord = { ...previousState[payload.id], ...payload.data };\n+            return addRecords([updatedRecord], previousState);\n+        }\n+        if (meta.fetch === UPDATE_MANY) {\n+            const updatedRecords = payload.ids\n+                .reduce((records, id) => records.concat(previousState[id]), [])\n+                .map(record => ({ ...record, ...payload.data }));\n+            return addRecords(updatedRecords, previousState);\n+        }\n+        if (meta.fetch === DELETE) {\n+            const { [payload.id]: removed, ...newState } = previousState;\n \n-        Object.defineProperty(newState, 'fetchedAt', {\n-            value: previousState.fetchedAt,\n-        });\n+            Object.defineProperty(newState, 'fetchedAt', {\n+                value: previousState.fetchedAt,\n+            });\n \n-        return newState;\n-    }\n-    if (type === CRUD_DELETE_MANY_OPTIMISTIC) {\n-        const newState = Object.entries(previousState)\n-            .filter(([key]) => !payload.ids.includes(key))\n-            .reduce((obj, [key, val]) => ({ ...obj, [key]: val }), {});\n+            return newState;\n+        }\n+        if (meta.fetch === DELETE_MANY) {\n+            const newState = Object.entries(previousState)\n+                .filter(([key]) => !payload.ids.includes(key))\n+                .reduce((obj, [key, val]) => ({ ...obj, [key]: val }), {});\n \n-        Object.defineProperty(newState, 'fetchedAt', {\n-            value: previousState.fetchedAt,\n-        });\n+            Object.defineProperty(newState, 'fetchedAt', {","path":"packages/ra-core/src/reducer/admin/resource/data.js","position":79,"original_position":79,"commit_id":"d81c87ef392053d8a7314829e3474e31a3c69173","original_commit_id":"d81c87ef392053d8a7314829e3474e31a3c69173","user":{"login":"ThieryMichel","id":4034399,"node_id":"MDQ6VXNlcjQwMzQzOTk=","avatar_url":"https://avatars2.githubusercontent.com/u/4034399?v=4","gravatar_id":"","url":"https://api.github.com/users/ThieryMichel","html_url":"https://github.com/ThieryMichel","followers_url":"https://api.github.com/users/ThieryMichel/followers","following_url":"https://api.github.com/users/ThieryMichel/following{/other_user}","gists_url":"https://api.github.com/users/ThieryMichel/gists{/gist_id}","starred_url":"https://api.github.com/users/ThieryMichel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThieryMichel/subscriptions","organizations_url":"https://api.github.com/users/ThieryMichel/orgs","repos_url":"https://api.github.com/users/ThieryMichel/repos","events_url":"https://api.github.com/users/ThieryMichel/events{/privacy}","received_events_url":"https://api.github.com/users/ThieryMichel/received_events","type":"User","site_admin":false},"body":"spread ?","created_at":"2018-12-20T13:56:03Z","updated_at":"2018-12-20T13:58:54Z","html_url":"https://github.com/marmelab/react-admin/pull/2684#discussion_r243279325","pull_request_url":"https://api.github.com/repos/marmelab/react-admin/pulls/2684","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/marmelab/react-admin/pulls/comments/243279325"},"html":{"href":"https://github.com/marmelab/react-admin/pull/2684#discussion_r243279325"},"pull_request":{"href":"https://api.github.com/repos/marmelab/react-admin/pulls/2684"}}},"pull_request":{"url":"https://api.github.com/repos/marmelab/react-admin/pulls/2684","id":240173077,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQwMTczMDc3","html_url":"https://github.com/marmelab/react-admin/pull/2684","diff_url":"https://github.com/marmelab/react-admin/pull/2684.diff","patch_url":"https://github.com/marmelab/react-admin/pull/2684.patch","issue_url":"https://api.github.com/repos/marmelab/react-admin/issues/2684","number":2684,"state":"open","locked":false,"title":"[RFR] Rely on meta to handle optimistic actions","user":{"login":"djhi","id":1122076,"node_id":"MDQ6VXNlcjExMjIwNzY=","avatar_url":"https://avatars2.githubusercontent.com/u/1122076?v=4","gravatar_id":"","url":"https://api.github.com/users/djhi","html_url":"https://github.com/djhi","followers_url":"https://api.github.com/users/djhi/followers","following_url":"https://api.github.com/users/djhi/following{/other_user}","gists_url":"https://api.github.com/users/djhi/gists{/gist_id}","starred_url":"https://api.github.com/users/djhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djhi/subscriptions","organizations_url":"https://api.github.com/users/djhi/orgs","repos_url":"https://api.github.com/users/djhi/repos","events_url":"https://api.github.com/users/djhi/events{/privacy}","received_events_url":"https://api.github.com/users/djhi/received_events","type":"User","site_admin":false},"body":"Context: https://marmelab.com/react-admin/Actions.html#using-a-custom-action-creator\r\n\r\nWe were relying on the action type to handle optimistic effects. This prevent custom actions to be handled optimistically too. \r\n\r\nConsider the following case: I have an `ACCEPT_CHANGE` and `REJECT_CHANGE` actions. Both will remove their targeted item from the `change` resource but will be caught by a custom saga to be applied on another resource. From the `change` resource perspective, they should be removed after being either accepted or rejected.\r\n\r\n```js\r\nexport const acceptChange = (\r\n    id: string,\r\n    previousData: any,\r\n    basePath: string\r\n) => ({\r\n    type: ACCEPT_CHANGE,\r\n    payload: { id, previousData },\r\n    meta: {\r\n        resource: 'changes',\r\n        fetch: DELETE,\r\n        onSuccess: {\r\n            notification: {\r\n                body: 'myapp.notification.accepted',\r\n                level: 'info',\r\n                messageArgs: {\r\n                    smart_count: 1,\r\n                },\r\n            },\r\n            redirectTo: 'list',\r\n            basePath,\r\n        },\r\n        onFailure: {\r\n            notification: {\r\n                body: 'ra.notification.http_error',\r\n                level: 'warning',\r\n            },\r\n        },\r\n    },\r\n});\r\n```","created_at":"2018-12-20T13:37:01Z","updated_at":"2018-12-20T13:58:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fb4e5d12b8cf41c5302e9fdca8ac865c0415b9e3","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":{"url":"https://api.github.com/repos/marmelab/react-admin/milestones/46","html_url":"https://github.com/marmelab/react-admin/milestone/46","labels_url":"https://api.github.com/repos/marmelab/react-admin/milestones/46/labels","id":3897524,"node_id":"MDk6TWlsZXN0b25lMzg5NzUyNA==","number":46,"title":"2.5.3","description":"Bugfix release, backwards compatible","creator":{"login":"fzaninotto","id":99944,"node_id":"MDQ6VXNlcjk5OTQ0","avatar_url":"https://avatars3.githubusercontent.com/u/99944?v=4","gravatar_id":"","url":"https://api.github.com/users/fzaninotto","html_url":"https://github.com/fzaninotto","followers_url":"https://api.github.com/users/fzaninotto/followers","following_url":"https://api.github.com/users/fzaninotto/following{/other_user}","gists_url":"https://api.github.com/users/fzaninotto/gists{/gist_id}","starred_url":"https://api.github.com/users/fzaninotto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fzaninotto/subscriptions","organizations_url":"https://api.github.com/users/fzaninotto/orgs","repos_url":"https://api.github.com/users/fzaninotto/repos","events_url":"https://api.github.com/users/fzaninotto/events{/privacy}","received_events_url":"https://api.github.com/users/fzaninotto/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":7,"state":"open","created_at":"2018-12-13T18:29:30Z","updated_at":"2018-12-20T13:37:05Z","due_on":"2018-12-20T08:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/marmelab/react-admin/pulls/2684/commits","review_comments_url":"https://api.github.com/repos/marmelab/react-admin/pulls/2684/comments","review_comment_url":"https://api.github.com/repos/marmelab/react-admin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/marmelab/react-admin/issues/2684/comments","statuses_url":"https://api.github.com/repos/marmelab/react-admin/statuses/d81c87ef392053d8a7314829e3474e31a3c69173","head":{"label":"marmelab:fix-optimistic-reducers","ref":"fix-optimistic-reducers","sha":"d81c87ef392053d8a7314829e3474e31a3c69173","user":{"login":"marmelab","id":3116319,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMxMTYzMTk=","avatar_url":"https://avatars1.githubusercontent.com/u/3116319?v=4","gravatar_id":"","url":"https://api.github.com/users/marmelab","html_url":"https://github.com/marmelab","followers_url":"https://api.github.com/users/marmelab/followers","following_url":"https://api.github.com/users/marmelab/following{/other_user}","gists_url":"https://api.github.com/users/marmelab/gists{/gist_id}","starred_url":"https://api.github.com/users/marmelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmelab/subscriptions","organizations_url":"https://api.github.com/users/marmelab/orgs","repos_url":"https://api.github.com/users/marmelab/repos","events_url":"https://api.github.com/users/marmelab/events{/privacy}","received_events_url":"https://api.github.com/users/marmelab/received_events","type":"Organization","site_admin":false},"repo":{"id":63226588,"node_id":"MDEwOlJlcG9zaXRvcnk2MzIyNjU4OA==","name":"react-admin","full_name":"marmelab/react-admin","private":false,"owner":{"login":"marmelab","id":3116319,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMxMTYzMTk=","avatar_url":"https://avatars1.githubusercontent.com/u/3116319?v=4","gravatar_id":"","url":"https://api.github.com/users/marmelab","html_url":"https://github.com/marmelab","followers_url":"https://api.github.com/users/marmelab/followers","following_url":"https://api.github.com/users/marmelab/following{/other_user}","gists_url":"https://api.github.com/users/marmelab/gists{/gist_id}","starred_url":"https://api.github.com/users/marmelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmelab/subscriptions","organizations_url":"https://api.github.com/users/marmelab/orgs","repos_url":"https://api.github.com/users/marmelab/repos","events_url":"https://api.github.com/users/marmelab/events{/privacy}","received_events_url":"https://api.github.com/users/marmelab/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/marmelab/react-admin","description":"A frontend Framework for building admin applications running in the browser on top of REST/GraphQL APIs, using ES6, React and Material Design","fork":false,"url":"https://api.github.com/repos/marmelab/react-admin","forks_url":"https://api.github.com/repos/marmelab/react-admin/forks","keys_url":"https://api.github.com/repos/marmelab/react-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marmelab/react-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marmelab/react-admin/teams","hooks_url":"https://api.github.com/repos/marmelab/react-admin/hooks","issue_events_url":"https://api.github.com/repos/marmelab/react-admin/issues/events{/number}","events_url":"https://api.github.com/repos/marmelab/react-admin/events","assignees_url":"https://api.github.com/repos/marmelab/react-admin/assignees{/user}","branches_url":"https://api.github.com/repos/marmelab/react-admin/branches{/branch}","tags_url":"https://api.github.com/repos/marmelab/react-admin/tags","blobs_url":"https://api.github.com/repos/marmelab/react-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marmelab/react-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marmelab/react-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/marmelab/react-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marmelab/react-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/marmelab/react-admin/languages","stargazers_url":"https://api.github.com/repos/marmelab/react-admin/stargazers","contributors_url":"https://api.github.com/repos/marmelab/react-admin/contributors","subscribers_url":"https://api.github.com/repos/marmelab/react-admin/subscribers","subscription_url":"https://api.github.com/repos/marmelab/react-admin/subscription","commits_url":"https://api.github.com/repos/marmelab/react-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/marmelab/react-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/marmelab/react-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/marmelab/react-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/marmelab/react-admin/contents/{+path}","compare_url":"https://api.github.com/repos/marmelab/react-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marmelab/react-admin/merges","archive_url":"https://api.github.com/repos/marmelab/react-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marmelab/react-admin/downloads","issues_url":"https://api.github.com/repos/marmelab/react-admin/issues{/number}","pulls_url":"https://api.github.com/repos/marmelab/react-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/marmelab/react-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/marmelab/react-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marmelab/react-admin/labels{/name}","releases_url":"https://api.github.com/repos/marmelab/react-admin/releases{/id}","deployments_url":"https://api.github.com/repos/marmelab/react-admin/deployments","created_at":"2016-07-13T07:58:54Z","updated_at":"2018-12-20T13:36:41Z","pushed_at":"2018-12-20T13:37:01Z","git_url":"git://github.com/marmelab/react-admin.git","ssh_url":"git@github.com:marmelab/react-admin.git","clone_url":"https://github.com/marmelab/react-admin.git","svn_url":"https://github.com/marmelab/react-admin","homepage":"http://marmelab.com/react-admin","size":100061,"stargazers_count":6293,"watchers_count":6293,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1355,"mirror_url":null,"archived":false,"open_issues_count":88,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1355,"open_issues":88,"watchers":6293,"default_branch":"master"}},"base":{"label":"marmelab:master","ref":"master","sha":"7dd24d480728160a449db0b1f3b6305e016959c3","user":{"login":"marmelab","id":3116319,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMxMTYzMTk=","avatar_url":"https://avatars1.githubusercontent.com/u/3116319?v=4","gravatar_id":"","url":"https://api.github.com/users/marmelab","html_url":"https://github.com/marmelab","followers_url":"https://api.github.com/users/marmelab/followers","following_url":"https://api.github.com/users/marmelab/following{/other_user}","gists_url":"https://api.github.com/users/marmelab/gists{/gist_id}","starred_url":"https://api.github.com/users/marmelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmelab/subscriptions","organizations_url":"https://api.github.com/users/marmelab/orgs","repos_url":"https://api.github.com/users/marmelab/repos","events_url":"https://api.github.com/users/marmelab/events{/privacy}","received_events_url":"https://api.github.com/users/marmelab/received_events","type":"Organization","site_admin":false},"repo":{"id":63226588,"node_id":"MDEwOlJlcG9zaXRvcnk2MzIyNjU4OA==","name":"react-admin","full_name":"marmelab/react-admin","private":false,"owner":{"login":"marmelab","id":3116319,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMxMTYzMTk=","avatar_url":"https://avatars1.githubusercontent.com/u/3116319?v=4","gravatar_id":"","url":"https://api.github.com/users/marmelab","html_url":"https://github.com/marmelab","followers_url":"https://api.github.com/users/marmelab/followers","following_url":"https://api.github.com/users/marmelab/following{/other_user}","gists_url":"https://api.github.com/users/marmelab/gists{/gist_id}","starred_url":"https://api.github.com/users/marmelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmelab/subscriptions","organizations_url":"https://api.github.com/users/marmelab/orgs","repos_url":"https://api.github.com/users/marmelab/repos","events_url":"https://api.github.com/users/marmelab/events{/privacy}","received_events_url":"https://api.github.com/users/marmelab/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/marmelab/react-admin","description":"A frontend Framework for building admin applications running in the browser on top of REST/GraphQL APIs, using ES6, React and Material Design","fork":false,"url":"https://api.github.com/repos/marmelab/react-admin","forks_url":"https://api.github.com/repos/marmelab/react-admin/forks","keys_url":"https://api.github.com/repos/marmelab/react-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marmelab/react-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marmelab/react-admin/teams","hooks_url":"https://api.github.com/repos/marmelab/react-admin/hooks","issue_events_url":"https://api.github.com/repos/marmelab/react-admin/issues/events{/number}","events_url":"https://api.github.com/repos/marmelab/react-admin/events","assignees_url":"https://api.github.com/repos/marmelab/react-admin/assignees{/user}","branches_url":"https://api.github.com/repos/marmelab/react-admin/branches{/branch}","tags_url":"https://api.github.com/repos/marmelab/react-admin/tags","blobs_url":"https://api.github.com/repos/marmelab/react-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marmelab/react-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marmelab/react-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/marmelab/react-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marmelab/react-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/marmelab/react-admin/languages","stargazers_url":"https://api.github.com/repos/marmelab/react-admin/stargazers","contributors_url":"https://api.github.com/repos/marmelab/react-admin/contributors","subscribers_url":"https://api.github.com/repos/marmelab/react-admin/subscribers","subscription_url":"https://api.github.com/repos/marmelab/react-admin/subscription","commits_url":"https://api.github.com/repos/marmelab/react-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/marmelab/react-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/marmelab/react-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/marmelab/react-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/marmelab/react-admin/contents/{+path}","compare_url":"https://api.github.com/repos/marmelab/react-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marmelab/react-admin/merges","archive_url":"https://api.github.com/repos/marmelab/react-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marmelab/react-admin/downloads","issues_url":"https://api.github.com/repos/marmelab/react-admin/issues{/number}","pulls_url":"https://api.github.com/repos/marmelab/react-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/marmelab/react-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/marmelab/react-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marmelab/react-admin/labels{/name}","releases_url":"https://api.github.com/repos/marmelab/react-admin/releases{/id}","deployments_url":"https://api.github.com/repos/marmelab/react-admin/deployments","created_at":"2016-07-13T07:58:54Z","updated_at":"2018-12-20T13:36:41Z","pushed_at":"2018-12-20T13:37:01Z","git_url":"git://github.com/marmelab/react-admin.git","ssh_url":"git@github.com:marmelab/react-admin.git","clone_url":"https://github.com/marmelab/react-admin.git","svn_url":"https://github.com/marmelab/react-admin","homepage":"http://marmelab.com/react-admin","size":100061,"stargazers_count":6293,"watchers_count":6293,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1355,"mirror_url":null,"archived":false,"open_issues_count":88,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1355,"open_issues":88,"watchers":6293,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/marmelab/react-admin/pulls/2684"},"html":{"href":"https://github.com/marmelab/react-admin/pull/2684"},"issue":{"href":"https://api.github.com/repos/marmelab/react-admin/issues/2684"},"comments":{"href":"https://api.github.com/repos/marmelab/react-admin/issues/2684/comments"},"review_comments":{"href":"https://api.github.com/repos/marmelab/react-admin/pulls/2684/comments"},"review_comment":{"href":"https://api.github.com/repos/marmelab/react-admin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/marmelab/react-admin/pulls/2684/commits"},"statuses":{"href":"https://api.github.com/repos/marmelab/react-admin/statuses/d81c87ef392053d8a7314829e3474e31a3c69173"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"ThieryMichel"}}