{"_id":"@elricb/webpack-promise","_rev":"1-c04660b163b3e5e986e757c07cac4b69","name":"@elricb/webpack-promise","description":"Wrap webpack import() Promise","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@elricb/webpack-promise","version":"1.0.0","description":"Wrap webpack import() Promise","main":"dist/index.js","scripts":{"build":"babel src/index.js --out-file dist/index.js --presets=es2015,stage-2"},"author":{"name":"elricb"},"license":"ISC","devDependencies":{"babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-preset-es2015":"^6.24.1","babel-preset-stage-2":"^6.24.1"},"dependencies":{},"_id":"@elricb/webpack-promise@1.0.0","_npmVersion":"5.3.0","_nodeVersion":"8.4.0","_npmUser":{"name":"elricb","email":"elricb@elricbest.com"},"dist":{"integrity":"sha512-OKr0vVAwVVbFZ/VONH5pIpqGG3V/0ShJNFGQjM2/un40bgu1uB8TzGDB8TuOZBoLRIgKJTV+3IjgZMtcgowjlg==","shasum":"f8ec9b23a3aece33fa08576e301bf30e62b34735","tarball":"https://registry.npmjs.org/@elricb/webpack-promise/-/webpack-promise-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDhddthdw4Z3Ln1L70ID0MrKogLgmaeMA5/n2c4xk26gAIgLyIOCpnfj0XtHLweHblI3/OWXp9V5GrpOmifgxq/lQA="}]},"maintainers":[{"name":"elricb","email":"elricb@elricbest.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/webpack-promise-1.0.0.tgz_1516385628101_0.07093999162316322"}}},"readme":"# webpack-promise\n\n## about\n\nDelayed Promise consumption.  Ensures thrown errors do not break processing.\n\n## E.G.\n\n```\nimport React from 'react';\nimport WebpackPromise from 'webpack-promise';\n\nclass UsePromise extends React.Component {\n    constructor(props) {\n        super(props);\n\n        // with async operations, you have to ensure the component\n        // hasn't unmounted before Promise finishes\n        this.active = true;\n    }\n    componentDidUpdate() {\n        this.loadComponent();\n    }\n    componentDidMount() {\n        this.loadComponent();\n    }\n    componentWillUnmount() {\n        this.active = false;\n    }\n    loadComponent() {\n        this.props.component\n            .then(Component => this.active && this.setState({ Component }))\n            .catch(err => console.error(err));\n    }\n    render() {\n        let { Component } = this.state;\n\n        if (!Component) {\n            return null;\n        }\n\n        return <Component>;\n    }\n}\n\nconst SetPromise = (props) => (\n    <UsePromise\n        component={new WebpackPromise(System.import('./' + props.path + '/index.jsx'))}\n    />\n);\n```\n\n## E.G. ID\n\n```\nimport React from 'react';\nimport NotFound from 'component/NotFound';\nimport WebpackPromise from 'webpack-promise';\n\nclass UsePromise extends React.Component {\n    constructor(props) {\n        super(props);\n        this.localPromise = new WebpackPromise();\n\n        // with async operations, you have to ensure the component\n        // hasn't unmounted before Promise finishes\n        this.active = true;\n    }\n    componentDidUpdate() {\n        this.loadComponent();\n    }\n    componentDidMount() {\n        this.loadComponent();\n    }\n    componentWillUnmount() {\n        this.active = false;\n    }\n    localComponent() {\n        this.localPromise\n            .promise(import('./' + wildcard + '/index.jsx'))\n            .id(wildcard, id => this.setState({ Component: null }))\n            .then(Component => this.setState({ Component }))\n            .catch(error => console.error(error));\n    }\n    loadComponent() {\n        this.props.component.id(\n            this.props.path,\n            () => this.setState({ Component: null })\n        )\n            .then(Component => this.active && this.setState({ Component }))\n            .catch(() => this.setState({ Component: NotFound }));\n    }\n    render() {\n        let { Component } = this.state;\n\n        if (!Component) {\n            return null;\n        }\n\n        return <Component>;\n    }\n}\n\nconst SetPromise = (props) => (\n    <UsePromise\n        path={props.path}\n        component={new WebpackPromise(System.import('./' + props.path + '/index.jsx'))}\n    />\n);\n```\n","maintainers":[{"name":"elricb","email":"elricb@elricbest.com"}],"time":{"modified":"2022-04-05T07:23:06.054Z","created":"2018-01-19T18:13:50.904Z","1.0.0":"2018-01-19T18:13:50.904Z"},"author":{"name":"elricb"},"license":"ISC","readmeFilename":"README.md"}