angular-lazy
Advanced tools
Comparing version 0.3.0-beta.0 to 0.3.0-beta.1
{ | ||
"name": "angular-lazy", | ||
"version": "0.3.0-beta.0", | ||
"version": "0.3.0-beta.1", | ||
"description": "Utilities for projects based on the [Angular Lazy Generator](https://github.com/matoilic/generator-angular-lazy)", | ||
@@ -22,7 +22,5 @@ "main": "src/angular-lazy.js", | ||
"devDependencies": { | ||
"eslint": "^3.14.0" | ||
}, | ||
"dependencies": { | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
@@ -29,0 +27,0 @@ "angular": "~1.5.0 || ~1.6.0", |
/** | ||
* Provides functionality to load components at runtime. | ||
* Provides functionality to lazily load components at runtime. | ||
*/ | ||
@@ -16,17 +16,28 @@ class ComponentLoaderService { | ||
/** | ||
* Loads a component with the given name. It will automatically look for the component in the components folder. | ||
* E.g. if you pass `popup` it will try to load the component from "components/popup/index". | ||
* Loads an Angular component and makes sure it is bootstrapped properly. | ||
* | ||
* @param {Promise} importFn | ||
* @param {Promise} importer A promise that resolves to a Angular module. This will usually be the return value of | ||
* an `import()` call. We do not call `import` in `loadComponent` itself because most module bundlers cannot handle | ||
* dynamic imports and are not able to split code properly if we use `import` in here. | ||
* @param {string} name Optional. If the Angular module to import is not exported as default, you can pass the name | ||
* under which to find the module. | ||
* @returns {Promise} | ||
*/ | ||
loadComponent(importFn) { | ||
return importFn.then(loadedComponent => { | ||
const componentName = loadedComponent.name || loadedComponent.default.name || loadedComponent; | ||
loadComponent(importer, name) { | ||
return importer.then((loadedComponent) => { | ||
let componentName; | ||
if (!this._$ocLazyLoad.isLoaded(componentName)) { | ||
return this._$ocLazyLoad.inject(componentName); | ||
if (name) { | ||
if (!loadedComponent[name]) { | ||
throw new Error(`No exported module found under "${name}", did you misspell it?`); | ||
} | ||
componentName = loadedComponent[name].name || loadedComponent[name]; | ||
} else if(loadedComponent.default) { | ||
componentName = loadedComponent.default.name || loadedComponent.default; | ||
} else { | ||
componentName = loadedComponent.name || loadedComponent; | ||
} | ||
return null; | ||
return this._$ocLazyLoad.inject(componentName); | ||
}); | ||
@@ -39,9 +50,14 @@ } | ||
* | ||
* @param {Promise} importFn | ||
* @param {String} identifier | ||
* @param {Promise} importer A promise that resolves to a Angular module. This will usually be the return value of | ||
* an `import()` call. We do not call `import` in `loadComponent` itself because most module bundlers cannot handle | ||
* dynamic imports and are not able to split code properly if we use `import` in here. | ||
* @param {String} identifier The identifier of the injectable which should be resolved from the imported Angular | ||
* module. | ||
* @param {string} exportName Optional. If the Angular module to import is not exported as default, you can pass | ||
* the name under which to find the module. | ||
* @returns {Promise} | ||
*/ | ||
resolve(importFn, identifier) { | ||
resolve(importer, identifier, exportName) { | ||
return this | ||
.loadComponent(importFn) | ||
.loadComponent(importer) | ||
.then(() => this._$injector.get(identifier)); | ||
@@ -48,0 +64,0 @@ } |
@@ -0,1 +1,5 @@ | ||
/** | ||
* Registers a handler to $futureStateProvider (ui-router-extras) which is used to load our routes at runtime. | ||
* @param $futureStateProvider | ||
*/ | ||
function routingConfig($futureStateProvider) { | ||
@@ -2,0 +6,0 @@ $futureStateProvider.stateFactory('load', [ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8695
102
0
1