Comments (5)
Hi @davesag I don't quite understand your request. Can you show a code example?
Do you mean you cannot detect a RSAA action? You can use isRSAA
to check if an action is RSAA.
from redux-api-middleware.
Once you have checked to see if an action isRSAA
and then you want to actually extract the types from it (or in my case I needed the meta
info from the flux action) you need a way to check action[RSAA].types
- if the RSAA
constant is not exposed then you need to define it yourself, which of course raises the risk that, should you change that constant in future, then the code will break. If you don't deprecate the constant then I can safely use it.
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
from redux-api-middleware.
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 getAction
š¤
So what you need is a reverse of createAction
. You can create your own function getAction
, in case of a major release to be easier to migrate
import { isRSAA, RSAA } from 'redux-api-middleware'
const getAction = (action) => isRSAA(action) ? action[RSAA] : action
from redux-api-middleware.
Exposing a getAction
function as you propose is a good idea. Iād use that instead of the RSAA
constant if it was avail.
from redux-api-middleware.
To assist in migration exposing getAction
would ideally happen before RSAA
was un-exposed :-)
from redux-api-middleware.
Related Issues (20)
- [SSR] Issue with webpack and token function since v3 HOT 4
- ReferenceError: fetch is not defined after upgrading HOT 14
- Tests example in Readme doesn't work in 3.0.1 HOT 5
- [Question] Passing actions to next rather than dispatching HOT 3
- Content-Security-Policy violation while using 3.0.X HOT 4
- Interest in Supporting Axios? HOT 6
- fetch error HOT 1
- APIError#reponse is undefined on non-successful (non-2xx) responses
- ok handler should be able to handle Promise<boolean>
- Question: firing multiple actions HOT 1
- Is this repository maintained? HOT 2
- Incorrect InternalError handler in case if a JSON request is invalid
- Error in ok handler HOT 1
- Testing RSAA api calls HOT 3
- Network request error creates non-serializable action HOT 5
- No way to associate an outgoing REQUEST with an incoming SUCCESS HOT 1
- How to use with redux-thunk and Typescript HOT 2
- Custom payload function is overwritten in RequestError & InternalError instances HOT 5
- contrary to documentation, meta is not honored for action type FAILURE
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-api-middleware.