forked from NativeScript/nativescript-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
27 lines (24 loc) · 729 Bytes
/
utils.ts
File metadata and controls
27 lines (24 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Utility method to ensure a NgModule is only imported once in a codebase, otherwise will throw to help prevent accidental double importing
* @param parentModule Parent module name
* @param moduleName The module name
*/
export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) {
if (parentModule) {
throw new Error(`${moduleName} has already been loaded. Import ${moduleName} in the AppModule only.`);
}
}
/**
* Utility method which will only fire the callback once ever
* @param fn callback to call only once
*/
export function once(fn: Function) {
let wasCalled = false;
return function wrapper() {
if (wasCalled) {
return;
}
wasCalled = true;
fn.apply(null, arguments);
};
}