JavaScript How to handle multiple interdependent sagas when rendering server-side?

I am implementing server-side rendering using

I am following the "real world" example provided in the redux-saga repository.

  1. rendering the application triggers componentWillMount, which dispatches actions GET_GEOLOCATION and GET_DATE. These async actions will resolve with SET_GEOLOCATION and SET_DATE.
  2. renderToString finishes rendering the application; END action terminates the saga listeners

The problem is that SET_GEOLOCATION and SET_DATE themselves are used to put a new action GET_MOVIES. However, by the time the SET_GEOLOCATION and SET_DATE are called, the saga listeners are no longer active (we terminated it after renderToString). Therefore, while GET_MOVIES will be dispatched, the GET_MOVIES action will not be picked and SET_MOVIE will never happen.

Server code:

app.get('*', (req, res) => {
  const history = createMemoryHistory({
    initialEntries: [
      req.url
    ]
  });
  const store = configureStore(undefined, history);
  const context = {};

  const rootComponent = <Provider store={store}>
    <StaticRouter context={context} location={req.url}>
      <Route component={RootRoute} />
    </StaticRouter>
  </Provider>;

  store
    .runSaga(rootSaga).done
    .then(() => {
      const body = renderToString(rootComponent);
      const response = renderHtml(body, store);

      res
        .send(response);
    })
    .catch((error) => {
      res
        .status(500)
        .send(error.message);
    });

  // Force componentWillMount to issue saga effects.
  renderToString(rootComponent);

  store.close();
});

Sagas:

const watchNewSearchCriteria = function *(): Generator<*, *, *> {
  yield takeLatest([
    SET_GEOLOCATION,
    SET_DATE
  ], function *() {
    const {
      coordinates,
      date
    } = yield select((state) => {
      return {
        coordinates: state.movieEventsView.location ? state.movieEventsView.location.coordinates : null,
        date: state.movieEventsView.date
      };
    });

    if (!coordinates || !date) {
      return;
    }

    yield put(getMovies({
      coordinates,
      date
    }));
  });
};

const watchGetMovies = function *() {
  yield takeLatest(GET_MOVIES, function *(action) {
    const result = yield call(getMovies, action.payload);

    yield put(setMovies(result));
  });
};

How to delay store.close until after there are no sagas that are in the state other than take?

Answer:1

I have a problem programming object-oriented in Javascript. I have the following: class Foo{ constructor(){...} ... a_needed_method(){...} ... a_method(){ ... ...

I have a problem programming object-oriented in Javascript. I have the following: class Foo{ constructor(){...} ... a_needed_method(){...} ... a_method(){ ... ...

  1. access parent this javascript
  2. access parent this
  3. react access parent this
  4. access the parent portal
  5. java access parent class this

I have an application where there could be anywhere between 1 - 30 POST ajax calls happening in parallel. Also these calls are being made to the same method in the controller. But when there are more ...

I have an application where there could be anywhere between 1 - 30 POST ajax calls happening in parallel. Also these calls are being made to the same method in the controller. But when there are more ...

I have attached a picture of the click action I want to run from the Chrome console, with various values passed. The button is highlighted in gray top right in the inspect element. It is the ...

I have attached a picture of the click action I want to run from the Chrome console, with various values passed. The button is highlighted in gray top right in the inspect element. It is the ...

  1. access angular controller from console
  2. access angular controller from javascript
  3. access angular controller variable in javascript
  4. access angular controller
  5. access controller scope angularjs
  6. access angularjs controller from console
  7. angular access controller scope from outside
  8. angular access controller from another module
  9. angular access controller variable
  10. angular access controller from directive
  11. angular access controller from html
  12. angular access controller variable from directive
  13. angular access controller method
  14. angular access controller functions
  15. angularjs access controller scope from directive
  16. angularjs access controller from directive
  17. angularjs access controller scope from service
  18. angularjs access controller from javascript
  19. angularjs access controller variable from directive
  20. angularjs access controller

I need a regex for javascript for matching "{any group of chars}" <-- where that last " is not preceeded by a \ examples: ... foo "bar" ... => "bar" ... foo"bar\"" ... => "bar\"" ... foo ...

I need a regex for javascript for matching "{any group of chars}" <-- where that last " is not preceeded by a \ examples: ... foo "bar" ... => "bar" ... foo"bar\"" ... => "bar\"" ... foo ...