Files
NativeScript/packages/core/utils/platform-check.ts
Igor Randjelovic f64355ba7a refactor: improved core barrel exports and Application class (#10286)
BREAKING CHANGES:

`Application.orientation` is no longer a function.

Migration: Remove `()` from the `Application.orientation()` call:
```diff
import { Application } from "@nativescript/core";

-console.log(Application.orientation());
+console.log(Application.orientation);
```


`Application.systemAppearance` is no longer a function.

Migration: Remove `()` from the `Application.systemAppearance()` call:
```diff
import { Application } from "@nativescript/core";

-console.log(Application.systemAppearance());
+console.log(Application.systemAppearance);
```
2023-05-25 07:45:39 -07:00

27 lines
700 B
TypeScript

/**
* @internal Util used for exporting opposing platform utils and warning the user if they are trying to access them.
*/
export function platformCheck(parent?: string) {
if (__DEV__) {
return new Proxy(
{},
{
get(_, prop) {
const propPretty = [parent, prop.toString()].join('.');
const hintPlatformCheck = global.isAndroid ? 'global.isIOS' : 'global.isAndroid';
// prettier-ignore
const errorMsg = [
`Trying to access "${propPretty}" without checking platform first.`,
`Hint: Use "${hintPlatformCheck}" to check platform before accessing "${propPretty}".`
].join('\n');
throw new Error(errorMsg);
},
}
);
}
return undefined;
}