-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please don't deprecate the RSAA constant #267
Comments
Hi @davesag I don't quite understand your request. Can you show a code example? |
Once you have checked to see if an action I need to do this because I have a payload function that wants to know what the meta data passed to the flux action that previously executed was. I've written this: import { isRSAA, RSAA } from 'redux-api-middleware'
const toAction = type => (typeof type === 'string' ? { type } : type)
const fluxAction = (rsaaAction, suffix) => {
if (!isRSAA(rsaaAction)) return rsaaAction
const actions = rsaaAction[RSAA].types.map(toAction)
if (suffix) {
const regex = new RegExp(suffix + '$', 'i')
return actions.find(({ type }) => type.match(regex) !== null)
}
return actions[0]
}
export default fluxAction using in a payload function like import { fluxAction } from 'utils'
import { getContentLikesWithId } from '../../selectors'
const successPayload = async (action, state) => {
const {
meta: { id }
} = fluxAction(action, 'SUCCESS')
const { count = 0 } = getContentLikesWithId(id)(state)
return {
count: count + 1,
currentUser: true
}
}
export default successPayload and also in a mock API Middleware function I use in my storybook stories import { action as clickAction } from '@storybook/addon-actions'
import { isRSAA } from 'redux-api-middleware'
import { fluxAction } from 'utils'
const mockApiMiddleware =
({ dispatch }) =>
next =>
async rsaaAction => {
if (!isRSAA(rsaaAction)) return next(rsaaAction)
const action = fluxAction(rsaaAction)
dispatch(action)
clickAction('dispatched')(action)
}
export default mockApiMiddleware |
Well mostly that action will not be deprecated, we just wanted to make it internal. And if that will happen it will be in a major release. And I think we will expose a new function So what you need is a reverse of import { isRSAA, RSAA } from 'redux-api-middleware'
const getAction = (action) => isRSAA(action) ? action[RSAA] : action |
Exposing a |
To assist in migration exposing |
In https://github.com/agraboso/redux-api-middleware/blob/master/src/RSAA.js#L6 you have deprecated the RSAA constant, however it's essential to be able to access that in the case where a
payload
function accepts thersaa action
and you need to deconstruct it to get (in my case) access to themeta
field supplied to the action.Please consider not deprecating this.
The text was updated successfully, but these errors were encountered: