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

    1

    Version

    6.2.0

    License

    MIT

    Last publish

    Collaborators

    • miblanchard-nfl
    • cwelch5
    • djwiebe
    • carakuei
    • mikenfl