How to use the umi/_runtimePlugin.apply function in umi

To help you get started, we’ve selected a few umi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crawlab-team / artipub / src / pages / .umi / umi.js View on Github external
req: ctx.req || {},
        res: ctx.res || {},
        ...initialProps,
      });
      props = plugins.apply('initialProps', {
        initialValue: props,
      });
    } else {
      // message activeRoute or getInitialProps not found
      console.log(
        !activeRoute
          ? `${pathname} activeRoute not found`
          : `${pathname} activeRoute's getInitialProps function not found`,
      );
    }
    const rootContainer = plugins.apply('rootContainer', {
      initialValue: React.createElement(require('./router').default, props),
    });
    const htmlTemplateMap = {};
    return {
      htmlElement:
        activeRoute && activeRoute.path
          ? htmlTemplateMap[activeRoute.path]
          : '',
      rootContainer,
      matchPath: activeRoute && activeRoute.path,
      g_initialData: props,
    };
  };
  // using project react-dom version
github crawlab-team / artipub / src / pages / .umi / umi.js View on Github external
initialValue: {},
      });
      // patch query object
      const location = history.location
        ? { ...history.location, query: getUrlQuery(history.location.search) }
        : {};
      props = await activeRoute.component.getInitialProps({
        route: activeRoute,
        isServer: true,
        location,
        // only exist in server
        req: ctx.req || {},
        res: ctx.res || {},
        ...initialProps,
      });
      props = plugins.apply('initialProps', {
        initialValue: props,
      });
    } else {
      // message activeRoute or getInitialProps not found
      console.log(
        !activeRoute
          ? `${pathname} activeRoute not found`
          : `${pathname} activeRoute's getInitialProps function not found`,
      );
    }
    const rootContainer = plugins.apply('rootContainer', {
      initialValue: React.createElement(require('./router').default, props),
    });
    const htmlTemplateMap = {};
    return {
      htmlElement:
github alitajs / alita / packages / umi-plugin-cache-route / renderRoutes.js View on Github external
render: function render(props) {
        var childRoutes = renderRoutes(route.routes, extraProps, {
          location: props.location
        });

        if (route.component) {
          var compatProps = getCompatProps(_objectSpread({}, props, {}, extraProps));
          var newProps = plugins.apply('modifyRouteProps', {
            initialValue: _objectSpread({}, props, {}, extraProps, {}, compatProps),
            args: {
              route: route
            }
          });
          var Component = route.component; // eslint-disable-next-line no-undef

          if (__IS_BROWSER && Component.getInitialProps) {
            var initialProps = plugins.apply('modifyInitialProps', {
              initialValue: {}
            });
            Component = wrapWithInitialProps(Component, initialProps);
          }

          return _react.default.createElement(Component, _extends({}, newProps, {
            route: route
github alitajs / alita / packages / umi-plugin-cache-route / renderRoutes.js View on Github external
var childRoutes = renderRoutes(route.routes, extraProps, {
          location: props.location
        });

        if (route.component) {
          var compatProps = getCompatProps(_objectSpread({}, props, {}, extraProps));
          var newProps = plugins.apply('modifyRouteProps', {
            initialValue: _objectSpread({}, props, {}, extraProps, {}, compatProps),
            args: {
              route: route
            }
          });
          var Component = route.component; // eslint-disable-next-line no-undef

          if (__IS_BROWSER && Component.getInitialProps) {
            var initialProps = plugins.apply('modifyInitialProps', {
              initialValue: {}
            });
            Component = wrapWithInitialProps(Component, initialProps);
          }

          return _react.default.createElement(Component, _extends({}, newProps, {
            route: route
          }), childRoutes);
        } else {
          return childRoutes;
        }
      }
    });
github alitajs / alita / packages / umi-plugin-cache-route / copy / renderRoutes.js View on Github external
const compatProps = getCompatProps({
                  ...props,
                  ...extraProps,
                });
                const newProps = plugins.apply('modifyRouteProps', {
                  initialValue: {
                    ...props,
                    ...extraProps,
                    ...compatProps,
                  },
                  args: { route },
                });
                let { component: Component } = route;
                // eslint-disable-next-line no-undef
                if (__IS_BROWSER && Component.getInitialProps) {
                  const initialProps = plugins.apply('modifyInitialProps', {
                    initialValue: {},
                  });
                  Component = wrapWithInitialProps(Component, initialProps);
                }
                return (
                  
                    {childRoutes}
                  
                );
              } else {
                return childRoutes;
              }
            }}
          />
github umijs / umi / packages / umi / src / renderRoutes.js View on Github external
render={props => {
              // TODO: ssr StaticRoute context hook, handle 40x / 30x
              const childRoutes = renderRoutes(route.routes, extraProps, {
                location: props.location,
              });
              if (route.component) {
                const compatProps = getCompatProps({
                  ...props,
                  ...extraProps,
                });
                const newProps = plugins.apply('modifyRouteProps', {
                  initialValue: {
                    ...props,
                    ...extraProps,
                    ...compatProps,
                  },
                  args: { route },
                });
                let { component: Component } = route;
                if (__IS_BROWSER && Component.getInitialProps) {
                  const initialProps = plugins.apply('modifyInitialProps', {
                    initialValue: {},
                  });
                  Component = wrapWithInitialProps(Component, initialProps);
                }
                return (
github umijs / umi / packages / umi / src / renderRoutes.js View on Github external
if (route.component) {
                const compatProps = getCompatProps({
                  ...props,
                  ...extraProps,
                });
                const newProps = plugins.apply('modifyRouteProps', {
                  initialValue: {
                    ...props,
                    ...extraProps,
                    ...compatProps,
                  },
                  args: { route },
                });
                let { component: Component } = route;
                if (__IS_BROWSER && Component.getInitialProps) {
                  const initialProps = plugins.apply('modifyInitialProps', {
                    initialValue: {},
                  });
                  Component = wrapWithInitialProps(Component, initialProps);
                }
                return (
                  
                    {childRoutes}
                  
                );
              } else {
                return childRoutes;
              }
            }}
          />
github crawlab-team / artipub / src / pages / .umi / umi.js View on Github external
activeRoute.component.getInitialProps
    ) {
      const initialProps = plugins.apply('modifyInitialProps', {
        initialValue: {},
      });
      props = activeRoute.component.getInitialProps
        ? await activeRoute.component.getInitialProps({
            route: activeRoute,
            isServer: false,
            location,
            ...initialProps,
          })
        : {};
    }
  }
  const rootContainer = plugins.apply('rootContainer', {
    initialValue: React.createElement(require('./router').default, props),
  });
  ReactDOM[window.g_useSSR ? 'hydrate' : 'render'](
    rootContainer,
    document.getElementById('root'),
  );
};
const render = plugins.compose(