{"action":"created","issue":{"url":"https://api.github.com/repos/erikras/redux-form/issues/1415","repository_url":"https://api.github.com/repos/erikras/redux-form","labels_url":"https://api.github.com/repos/erikras/redux-form/issues/1415/labels{/name}","comments_url":"https://api.github.com/repos/erikras/redux-form/issues/1415/comments","events_url":"https://api.github.com/repos/erikras/redux-form/issues/1415/events","html_url":"https://github.com/erikras/redux-form/issues/1415","id":168084074,"number":1415,"title":"[v6 rc3] Detecting if form value actually changed in reducer plugin","user":{"login":"webholics","id":101841,"avatar_url":"https://avatars.githubusercontent.com/u/101841?v=3","gravatar_id":"","url":"https://api.github.com/users/webholics","html_url":"https://github.com/webholics","followers_url":"https://api.github.com/users/webholics/followers","following_url":"https://api.github.com/users/webholics/following{/other_user}","gists_url":"https://api.github.com/users/webholics/gists{/gist_id}","starred_url":"https://api.github.com/users/webholics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webholics/subscriptions","organizations_url":"https://api.github.com/users/webholics/orgs","repos_url":"https://api.github.com/users/webholics/repos","events_url":"https://api.github.com/users/webholics/events{/privacy}","received_events_url":"https://api.github.com/users/webholics/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-28T12:31:50Z","updated_at":"2016-12-22T17:11:52Z","closed_at":null,"body":"I've written a reducer plugin like this:\n\n```\n  const plugins = {\n    'logistic-section': (state, action) => {\n      switch (action.type) {\n        // Reset fieldB which dependd on fieldA if the value\n        // has changed.\n        case actionTypes.CHANGE:\n          if (action.meta.field === 'fieldA') {\n            return {\n              ...state,\n              values: { // Clear some values.\n                ...state.values,\n                fieldB: undefined,\n              },\n              fields: { // Also clear field state, too (touched, etc.).\n                ...state.fields,\n                fieldB: undefined,\n              },\n            };\n          }\n\n          return state;\n        default:\n          return state;\n      }\n    },\n  };\n\n  return formReducer.plugin(plugins);\n```\n\nHowever it is possible that the CHANGE action never changed the value in the state because the `payload` within the action was the same as the field value in the state. This happens e.g. when the user clicks on an already active radio button. Therefore I would like to detect within the plugin if the value actually changed. But since the state given into the plugin was already updated by the redux form reducer I don't have access to the old state and cannot detect that change.\n\nI see 2 solutions to this problem:\n1. Give the old state as third parameter to the plugin function.\n2. Refactor the plugin feature to behave more like a middleware. This means the plugin should be able to manipulate state before **and** after the actual form reducer.\n"},"comment":{"url":"https://api.github.com/repos/erikras/redux-form/issues/comments/268845422","html_url":"https://github.com/erikras/redux-form/issues/1415#issuecomment-268845422","issue_url":"https://api.github.com/repos/erikras/redux-form/issues/1415","id":268845422,"user":{"login":"optyler","id":10259,"avatar_url":"https://avatars.githubusercontent.com/u/10259?v=3","gravatar_id":"","url":"https://api.github.com/users/optyler","html_url":"https://github.com/optyler","followers_url":"https://api.github.com/users/optyler/followers","following_url":"https://api.github.com/users/optyler/following{/other_user}","gists_url":"https://api.github.com/users/optyler/gists{/gist_id}","starred_url":"https://api.github.com/users/optyler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/optyler/subscriptions","organizations_url":"https://api.github.com/users/optyler/orgs","repos_url":"https://api.github.com/users/optyler/repos","events_url":"https://api.github.com/users/optyler/events{/privacy}","received_events_url":"https://api.github.com/users/optyler/received_events","type":"User","site_admin":false},"created_at":"2016-12-22T17:11:52Z","updated_at":"2016-12-22T17:11:52Z","body":"Hi! any updates for this? actually I'm doing it with `callbacks` on `onChange` events... that I think is ugly..."}}
{"actor":{"display_login":"optyler"}}