Skip to content

Commit 4f0fba9

Browse files
hdeshevsis0k0
authored andcommitted
fix(platform-providers): Remove a circular import.
1 parent 26a8d34 commit 4f0fba9

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

nativescript-angular/platform-common.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if (global.___TS_UNUSED) {
2626
}
2727

2828
import { rendererLog, rendererError } from "./trace";
29-
import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider } from "./platform-providers";
29+
import { PAGE_FACTORY, PageFactory, defaultPageFactoryProvider, setRootPage } from "./platform-providers";
3030

3131
import { start, setCssFileName } from "application";
3232
import { topmost, NavigationEntry } from "ui/frame";
@@ -61,20 +61,11 @@ export const COMMON_PROVIDERS = [
6161

6262
export class NativeScriptPlatformRef extends PlatformRef {
6363
private _bootstrapper: BootstrapperAction;
64-
private static _rootPageRef: WeakRef<Page>;
6564

6665
constructor(private platform: PlatformRef, private appOptions?: AppOptions) {
6766
super();
6867
}
6968

70-
static set rootPage(page: Page) {
71-
NativeScriptPlatformRef._rootPageRef = new WeakRef(page);
72-
}
73-
74-
static get rootPage(): Page {
75-
return NativeScriptPlatformRef._rootPageRef.get();
76-
}
77-
7869
bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>> {
7970
this._bootstrapper = () => this.platform.bootstrapModuleFactory(moduleFactory);
8071

@@ -158,7 +149,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
158149
const navEntry: NavigationEntry = {
159150
create: (): Page => {
160151
let page = pageFactory({ isBootstrap: true, isLivesync });
161-
NativeScriptPlatformRef.rootPage = page;
152+
setRootPage(page);
162153
if (this.appOptions) {
163154
page.actionBarHidden = this.appOptions.startPageActionBarHidden;
164155
}

nativescript-angular/platform-providers.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ if (global.___TS_UNUSED) {
1515
})();
1616
}
1717

18+
let _rootPageRef: WeakRef<Page>;
19+
20+
export function setRootPage(page: Page): void {
21+
_rootPageRef = new WeakRef(page);
22+
}
23+
24+
export function getRootPage(): Page {
25+
return _rootPageRef && _rootPageRef.get();
26+
}
27+
1828
// Use an exported function to make the AoT compiler happy.
1929
export function getDefaultPage(): Page {
2030
const frame = topmost();
21-
if (frame) {
22-
return frame.currentPage;
23-
} else {
24-
return null;
25-
}
31+
return getRootPage() || (frame && frame.currentPage);
2632
}
2733

2834
export const defaultPageProvider = { provide: Page, useFactory: getDefaultPage };

nativescript-angular/renderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import { escapeRegexSymbols } from "utils/utils";
1212
import { Device } from "platform";
1313

1414
import { ViewUtil } from "./view-util";
15-
import { APP_ROOT_VIEW, DEVICE } from "./platform-providers";
15+
import { APP_ROOT_VIEW, DEVICE, getRootPage } from "./platform-providers";
1616
import { NgView } from "./element-registry";
1717
import { rendererLog as traceLog } from "./trace";
18-
import { NativeScriptPlatformRef } from "./platform-common";
1918

2019
// CONTENT_ATTR not exported from NativeScript_renderer - we need it for styles application.
2120
const COMPONENT_REGEX = /%COMP%/g;
@@ -44,8 +43,9 @@ export class NativeScriptRendererFactory implements RendererFactory2 {
4443

4544
private setRootNgView(rootView: any) {
4645
if (!rootView) {
47-
rootView = NativeScriptPlatformRef.rootPage || <NgView><any>topmost().currentPage;
46+
rootView = getRootPage() || topmost().currentPage;
4847
}
48+
4949
rootView.nodeName = "NONE";
5050
this.rootNgView = rootView;
5151
}

0 commit comments

Comments
 (0)