npm

Need private packages and team management tools?Check out npm Orgs. »

react-wildcat-ensure

6.2.0 • Public • Published

react-wildcat-ensure

npm package

A wrapper for System.import that behaves like Webpack's require.ensure:

  • initial import calls are asynchronous
  • subsequent import calls returns a synchronous cached import response

Designed for compatibility with React Router's asynchronous route loading.

Installation

jspm:

jspm install react-wildcat-ensure

npm:

npm install react-wildcat-ensure

Usage

Importing a single module:

import ensure from "react-wildcat-ensure";
 
// Lazy loaded component
export function getComponent(location, cb) {
    ensure("./AsyncComponent.js", module, (err, module) => {
        return cb(err, module);
    });
}

Importing a key/value hash of modules:

import ensure from "react-wildcat-ensure";
 
// Lazy loaded index route
export function getIndexRoute(location, cb) {
    ensure({
      header: "./AsyncHeader.js",
      component: "./AsyncComponent.js"
    }, module, (err, modules) => {
        return cb(err, modules);
    });
}

Importing an array of modules:

import ensure from "react-wildcat-ensure";
 
// Lazy loaded child routes
export function getChildRoutes(location, cb) {
    ensure([
      "./AsyncChildRouteOne.js",
      "./AsyncChildRouteTwo.js"
    ], module, (err, modules) => {
        return cb(err, modules);
    });
}

License

MIT

Keywords

none

install

npm i react-wildcat-ensure

Downloadsweekly downloads

28

version

6.2.0

license

MIT

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability