forked from oskariorg/oskari-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request oskariorg#2792 from ZakarFin/bundle-lazy-loader
Oskari 3.0 bundle lazy-loader
- Loading branch information
Showing
9 changed files
with
143 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const _bundleRegistry = {}; | ||
const _availableLazyBundles = {}; | ||
|
||
export const BundleRegister = { | ||
/** | ||
* @method bundle | ||
* Register bundle that is loaded and available for starting | ||
* | ||
* @param {string} bundlename Bundle name | ||
* @param {Function} factory function returns a bundle instance | ||
*/ | ||
bundle: (bundleId, value) => { | ||
if (value) { | ||
_bundleRegistry[bundleId] = value; | ||
} | ||
return _bundleRegistry[bundleId]; | ||
}, | ||
/** | ||
* @method lazyBundle | ||
* Register bundle for lazy-loading/run-time loading with ES import() | ||
* | ||
* @param {string} bundlename Bundle name | ||
* @param {Function} loader function that returns an promise that resolve to the module to be loaded | ||
*/ | ||
lazyBundle: (bundleId, loader) => { | ||
if (loader) { | ||
if (!_availableLazyBundles[bundleId]) { | ||
_availableLazyBundles[bundleId] = []; | ||
} | ||
_availableLazyBundles[bundleId].push(loader); | ||
} | ||
return _availableLazyBundles[bundleId]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.