Skip to content

Trigger all component hooks  #38

@mrasoahaingo

Description

@mrasoahaingo

Does Redial supports multiple trigger when many components is displayed on the same page? It's on an universal implementation

For example:

article.js

@provideHook({
  fetch: //...
})
class ArticlePage extends React.Component {
  //...
  render() {
    return (
        <article>
          ...
          <List/>
        </article>
    )
  }
}

list.js

@provideHook({
  fetch: //...
})
class List extends React.Component {
  //...
  render() {
    return (
        <ul>
          ...
        </ul>
    )
  }
}

client.js

      const { components } = renderProps;
      const { dispatch } = store;
      const locals = {
        path: renderProps.location.pathname,
        query: renderProps.location.query,
        params: renderProps.params,
        dispatch
      };

      if (window.__INITIAL_STATE__) {
        delete window.__INITIAL_STATE__;
      } else {
        trigger('fetch', components, locals);
      }

      trigger('defer', components, locals);

server.js

      const locals = {
        path: renderProps.location.pathname,
        query: renderProps.location.query,
        params: renderProps.params,
        dispatch
      };

      trigger('fetch', components, locals)
        .then(() => {

          const html = template({
            root: renderToStaticMarkup(
              <Provider store={store}>
                <RouterContext {...renderProps} />
              </Provider>
            ),
            initialState: getState(),
            jsBundle: clientAssets.main.js,
            cssBundle: clientAssets.main.css,
          });

          response.status(200).send(`<!doctype html>${html}`);

        }, () => {
          response.status(503).send('Fail on fetching data');
        })
        .catch(() => {
          response.status(500).send('Fail on fetching data');
        });

Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions