Skip to content

Commit

Permalink
feat(index): add PLATFORM.moduleName
Browse files Browse the repository at this point in the history
implements the basics for #17 - an interface and a basic implementation returning the moduleName
  • Loading branch information
niieani committed Dec 10, 2016
1 parent 06c83e3 commit da92298
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,51 @@ interface Platform {
* @param capture Specifies whether the listener to be removed was registered as a capturing listener or not.
*/
removeEventListener(eventName: string, callback: Function, capture?: boolean): void;

/**
* Reference to the Loader Class (set after the loader has been first imported)
*/
Loader: any;
/**
* Resolves a module name to a path resolvable by the loader. By default returns the first parameter.
* It is recommended to use this for all dynamic imports as it enables static analysis
* and optionally allows adding custom metadata used by the build step.
*
* References to this method should always literally call `PLATFORM.moduleName(...)`.
* This enables the build step to statically optimize the code by replacing the reference with a string.
*
* @param moduleName Absolute or relative path to the module.
* @param options Optional options used during the static analysis that inform how to process the module.
*/
moduleName(moduleName: string, options?: ModuleNameOptions): string;
}

/**
* Options used during the static analysis that inform how to process a given module.
*/
interface ModuleNameOptions {
/**
* Use code-splitting by separating out the requested module into its own file
*/
lazy?: boolean;
/**
* Add the module to a chunk by name
*/
chunk?: string;
/**
* When provided, use a RegExp instead of the moduleName during static analysis
*/
moduleRegex?: RegExp;
}

/**
* The singleton instance of the Platform API.
*/
export const PLATFORM: Platform = {
noop: function() {},
eachModule() {}
eachModule() {},
moduleName(moduleName) {
return moduleName;
}
};

PLATFORM.global = (function() {
Expand Down

0 comments on commit da92298

Please sign in to comment.