Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 19 18:24
    rgbkrk commented #477
  • Jul 04 05:34
    paritosh149 commented #738
  • Jul 01 18:32
    jayphelps commented #738
  • Jul 01 18:32
    jayphelps closed #738
  • Jul 01 18:32
    jayphelps commented #738
  • Jul 01 18:31
    jayphelps commented #738
  • Jun 29 10:37
    paritosh149 commented #738
  • Jun 24 22:02
    getkey commented #738
  • Jun 24 21:59
    getkey commented #738
  • Jun 24 20:33
    jayphelps commented #738
  • Jun 24 20:32
    jayphelps commented #738
  • Jun 24 20:31
    wirdehall commented #738
  • Jun 24 20:30
    wirdehall commented #738
  • Jun 24 20:29
    jayphelps commented #738
  • Jun 24 20:29

    jayphelps on gh-pages

    update book update book (compare)

  • Jun 24 20:27

    jayphelps on master

    chore(publish): v2.0.0 chore(scripts/publish.sh): add … Merge branch 'master' of github… (compare)

  • Jun 24 20:25

    jayphelps on v2.0.0

    (compare)

  • Jun 24 20:25

    jayphelps on master

    chore(publish): v2.0.0 (compare)

  • Jun 24 20:20

    jayphelps on master

    chore(package-lock): update loc… (compare)

  • Jun 24 20:20
    jayphelps commented #750
Kishu
@SRachamim
Hey. We're new to redux-observable and we started integrating it into our existing code-base. Out goal: decouple state and logic from the UI layer by lifting the state and put it on redux. We have one big concern though: performance. What is the best way to complete and add epics on run time? We know how to technically do that ('Adding New Epics Asynchronously/Lazily" section on the website explain it nicely), but we want to know if there is some known pattern to manage it cleanly.
Kevin Ghadyani
@Sawtaytoes
@SRachamim What's your structure look like? Statically assigning epics is all I do. If I need to dynamically load something, I use mergeMap to create a new inner observable and takeUntil to kill it based on some action type.
varun85jobs
@varun85jobs
Hello, I am using rxjs, redux-observable in my project. Everything works fine when I run it in browser i.e. epics get called etc. However, when running e2e written in cypress, epics are not fired/called at all. I have posted the question on stackoverflow.
https://stackoverflow.com/questions/67419785/rxjs-epics-not-getting-triggered-in-cypress
Doe anyone have an idea why this must be happening.
Kevin Ghadyani
@Sawtaytoes
@varun85jobs My only guess is your configuration is messed up e2e, or you're having errors because the environment is different somehow.
varun85jobs
@varun85jobs
Hello @Sawtaytoes , what is confusing me is that e2e tests run fine when the store creation is moved within child project from the dependency project. It is only when store creation is within the dependency prject that's when the issue occurs. So, I am not sure what might be going wrong.
Kevin Ghadyani
@Sawtaytoes

@varun85jobs I'm not quite sure what your issue is. I've read it multiple times, and I don't have a good grasp of the situation.

It seems weird that running unit tests would break Redux-Observable unless you're trying to execute before the Redux-Observable middleware has finished starting up.

varun85jobs
@varun85jobs
@Sawtaytoes Thanks for taking time to read the question. The issue is that when I create the redux store in the child project, the epics are fired however when I move the redux store creation login in the dependency/library, the epics don't get fired. Also this only happens in the e2e cypress tests only. Everything works fine when run in the browser. Hope it clears the things.
Galileo Sanchez
@galileopy
image.png

Hi guys, I am having a pretty frustrating error trying to add redux-observables to an existing codebase, they're using redux toolkits with custom store enhancers.

export const configureStore = () => {
  const epicMiddleware = createEpicMiddleware();
  const store = configureStoreToolkit({
    reducer,
    enhancers: [
      createApiEnhancer({
        baseUrl: API_ROOT,
        tokenRefreshUrl: `${API_ROOT}${ApiPath.RefreshToken}`,
        maxQueueSize: 20,
        defaultFetchOptions: {
          headers: {
            'Content-Type': 'application/json',
          },
        },
      }),
    ],
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware().concat(epicMiddleware),
  });

  epicMiddleware.run(rootEpic);
  return store;
};

I tried that, and

export const configureStore = () => {
  const epicMiddleware = createEpicMiddleware();
  const store = configureStoreToolkit({
    reducer,
    enhancers: [
      applyMiddleware(epicMiddleware),
      createApiEnhancer({
        baseUrl: API_ROOT,
        tokenRefreshUrl: `${API_ROOT}${ApiPath.RefreshToken}`,
        maxQueueSize: 20,
        defaultFetchOptions: {
          headers: {
            'Content-Type': 'application/json',
          },
        },
      }),
    ],
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware().concat(epicMiddleware),
  });

  epicMiddleware.run(rootEpic);
  return store;
};

But I keep getting this error.

image.png

that error

my root epic is just this
const log = (action$, state$) => action$.pipe(tap(log), ignoreElements());
Now the implementation of createApiEnhancers applys a lot of mws, and I am not sure if the problem is there or in my epicMw setup which seems pretty standard
Galileo Sanchez
@galileopy
From the top of your head, is there something that might break epicMiddleware? like adding thunks before epics, or having promise actions(which we have for some obscure reason)....
lchan
@leochan007
how to use redux-obs to simulate state machine?
now i use rerender to trigger the state machine transform.
Kevin Ghadyani
@Sawtaytoes
@leochan007 Not sure what you're asking. Could you post some code?

@varun85jobs

@Sawtaytoes Thanks for taking time to read the question. The issue is that when I create the redux store in the child project, the epics are fired however when I move the redux store creation login in the dependency/library, the epics don't get fired. Also this only happens in the e2e cypress tests only. Everything works fine when run in the browser. Hope it clears the things.

Make sure you're including Redux-Observable as a dependency in the library. I can't think what would cause this. Without seeing code or a sample project, it's hard.

Mitchell Cravens
@thetoxicavenger
hi. I'm having trouble implementing a callback after an epic dispatches a success action. If I were using a thunk, it wouldn't be a problem - i would wrap the thunk in a promise then call resetForm() when it resolves. however, since ostensibly redux-observable can't do that, I'm at a loss for what to do. thanks!
// form component
<Form
  handleSubmit={(values, { resetForm }) => {
    const body = JSON.stringify(values);
    dispatch(create(body));

    // form needs to be cleared once response data is saved to the store
    resetForm();
  }
>{children}</Form>
// create epic
export const createUserEpic = action$ =>
  action$.pipe(
    ofType(create.type),
    mergeMap(action =>
      ajax
        .post("https://jsonplaceholder.typicode.com/users", action.payload, {
          "Content-Type": "application/json",
          Accept: "application/json"
        })
        .pipe(map(res => created(res.response))) // want to call resetForm after this has happened
    )
  );
Evert Bouw
@evertbouw
@galileopy are you using rxjs 7 and redux-observable@next?
I suspect a version conflict
@thetoxicavenger this is a bit of a limit in the reactivity model. Your success action could set some state, and you can then trigger an action in your component when that state changes
5 replies
NTN Nhân
@ntnhan0605
What do you create structure folder for redux?
Kevin Ghadyani
@Sawtaytoes
@ntnhan0605 Depends on the project. These days, I typically keep everything Redux in a single folder. I don't mix it with React as it's a separate piece of code entirely.
Dimitri Dumont
@dimitridumont

Hello, I recently discovered redux-observable. While trying to combine multiple Epics I got this error in my test suite with Jest:

TypeError: Cannot read property 'apply' of undefined (redux-observable\lib\cjs\combineEpics.js:26:26)

While in the application I have no worries and all my tests also pass

From what I could see this is from one of my Epics which would be undefined, but I don't understand why:

export const getPostsOfUserEpic: Epic = (action$) =>
    action$.pipe(
        ofType(GET_POSTS_LIST_OF_USER_REQUEST),
        mergeMap((action: any) => {
            const { userID, page, type, actionType } = action.payload

            const params: { page: number; type?: string } = { page }
            if (type) params.type = type

            return from(
                HttpClient.get(`/users/${userID}/posts`, {
                    params,
                })
            ).pipe(
                map(({ data }) =>
                    getPostsOfUserSuccess({
                        actionType,
                        type,
                        data,
                    })
                ),
                catchError((error) =>
                    of(actionFailed(GET_POSTS_LIST_FAIL, error))
                ),
                takeUntil(action$.pipe(ofType(GET_POSTS_LIST_CANCEL)))
            )
        })
    )

My rootEpic imports two combineEpics (postsListEpic and userProfileEpic) which are epics:

const epics: Epic[] = [postsListEpic, userProfileEpic]

export const rootEpic = combineEpics(...epics)
Kevin Ghadyani
@Sawtaytoes
@dimitridumont very strange. Are you using a mock Redux or something?
NTN Nhân
@ntnhan0605

@ntnhan0605 Depends on the project. These days, I typically keep everything Redux in a single folder. I don't mix it with React as it's a separate piece of code entirely.

Thanks

NTN Nhân
@ntnhan0605
Do you know this issue: this.schedulerActionCtor is not a constructor?
Dimitri Dumont
@dimitridumont
@Sawtaytoes i use mock adapter axios to mock axios in my integration tests. But in unit tests, i use my in-memory repository
Kevin Ghadyani
@Sawtaytoes
@dimitridumont I'd check to make sure of a few things. For instance, it's looking for apply of undefined. That makes me think one of the epics doesn't exist. If you look at the source of combineEpics, I'm sure it will say something like Arguments.prototype.apply(). The only reason this happens is if one of your epics doesn't exist or can't be found for the unit tests.
image.png
@dimitridumont Look at this, it calls .apply in two situations, one for RxJS's merge function and another for epic.apply. The latter is more-likely your issue where a passed-in epic isn't a function.
Dimitri Dumont
@dimitridumont

@Sawtaytoes
Hello, thank you for your answers

Indeed, the epic does not seem to be defined or is null. However, I do not see why?

jakubmarcinowski
@jakubmarcinowski

alt

Hi, sadly im getting this error after using
const epicMiddleware = createEpicMiddleware()

Kevin Ghadyani
@Sawtaytoes
@jakubmarcinowski For some reason, I can't click that thumbnail to make it larger. Could you paste the top portion of the error in triple backticks?
@dimitridumont That's a good question. I'm wondering if you're exporting differently with Babel (in the .babelrc) than your local dev env.
Naval Saini
@flipflopapp
Screenshot 2021-06-03 at 3.55.12 PM.png
Facing an error -> this.schedulerActionCtor is not a constructor I need help with this error. I get it from epicMiddleware.run(rootEpic) . Here is the source code - https://github.com/flipflopapp/react-redux-epics-typescript-2021-boilerplate (can anyone help out)
Kevin Ghadyani
@Sawtaytoes
@flipflopapp Is this related to RxJS 7?
Naval Saini
@flipflopapp
@Sawtaytoes yes this is related to RXJS 7 (form package.json - "rxjs": "^7.1.0"). This is easy to reproduce,
  1. clone https://github.com/flipflopapp/react-redux-epics-typescript-2021-boilerplate,
  2. install pacakges (yarn install) and
  3. run app (yarn run start)
(I wonder if I missed a configuration step, and therefore asked here. Since I was doing this on side, not really urgent for me.)
Michael Gauthier
@gauthierm
Is it a reasonable pattern to have action payloads that are not used by reducers but are used in an epic? For sign-in I have an action that has an email/password payload. I don't really want to store the values in the store, just access them in the epic.
There is a reducer that runs on the action, but the reducer doesn't use the email/password values.
Kevin Ghadyani
@Sawtaytoes
@flipflopapp Sadly, I've not used RxJS 7 yet so I wouldn't know, but you're not the first person to note something.
@gauthierm Correct. That's a common pattern. You shouldn't think of actions being only for reducers when using Redux-Observable because actions can now be specifically for triggering events.
dalehurwitz
@dalehurwitz

Hey all,

I'm working on an epic that will asynchronously load another epic. While the epic is loading, all actions will be buffered and eventually passed through this epic.

The current implementation I'm working with:

const lazyEpic =
    (getEpicPromise: () => Promise<Epic>) =>
    (
        action$: ActionsObservableType,
        store: MiddlewareAPI,
        dependencies: BoardEpicDependencies,
    ): ObservableType<Action> => {
        const epic$ = Observable.fromPromise(getEpicPromise());

        // Buffer all actions before epic is loaded
        const actionsBeforeEpic$ = action$.buffer(epic$);

        // Run the buffered actions through the deferred epic
        const bufferedResults$ = actionsBeforeEpic$.mergeMap((actions) =>
            epic$.mergeMap((epic) => epic(ActionsObservable.of(...actions), store, dependencies)),
        );

        // Pass the active action$ stream to the deferred epic
        const normalResults$ = epic$.mergeMap((epic) => epic(action$, store, dependencies));

        return Observable.merge(normalResults$, bufferedResults$);
    };

The problem I'm having is this line, which causes a stack overflow/range error, and I can't quite figure out why:

const bufferedResults$ = actionsBeforeEpic$.mergeMap((actions) =>
            epic$.mergeMap((epic) => epic(ActionsObservable.of(...actions), store, dependencies)),  // Returning epic(ActionsObservable.of(...actions), store, dependencies)) is the culprit
        );

Wondering if there's any suggestions or obvious flaws in this implementation?

Kevin Ghadyani
@Sawtaytoes
@galileopy This looks like an error from RxJS v7. Is that what you're using?
Kevin Ghadyani
@Sawtaytoes

@dalehurwitz This buffering could be handled by dispatching actions and collecting them in another epic. No need to leave the pipeline and make a bunch of variables.

I'm trying to decipher your epic and can't understand what it's doing. There's no reason to ever call epic(action$, .... etc) in another epic. Just dispatch an action (that no reducer uses) and be done with it.

dalehurwitz
@dalehurwitz
@Sawtaytoes essentially epic(action$, store, dependencies); is adding the async-loaded epic to the root
dalehurwitz
@dalehurwitz
I think I see what you're getting at though!