chore: remove critical circular dependencies (#8114)

* chore: remove critical circular dependencies

* chore: fix tslint errors

* chore: remove platform specific types from interfaces

* chore: update unit tests polyfills

* fix: incorrect null check

* chore: update api.md file

* test: improve test case

* chore: apply comments

* test: avoid page style leaks in tests
This commit is contained in:
Martin Yankov
2019-11-28 13:36:34 +02:00
committed by Alexander Vakrilov
parent 5b647bd809
commit 0ffc790d82
72 changed files with 1958 additions and 1307 deletions

View File

@@ -1,6 +1,9 @@
import { Font as FontDefinition, ParsedFont } from "./font";
import { Font as FontDefinition } from "./font";
import { ParsedFont } from "./font-interfaces";
import { makeValidator, makeParser } from "../core/properties";
export * from "./font-interfaces";
export abstract class Font implements FontDefinition {
public static default = undefined;

View File

@@ -0,0 +1,12 @@
export type FontStyle = "normal" | "italic";
export type FontWeight = "100" | "200" | "300" | "normal" | "400" | "500" | "600" | "bold" | "700" | "800" | "900";
export interface ParsedFont {
fontStyle?: FontStyle;
fontVariant?: string;
fontWeight?: FontWeight;
lineHeight?: string;
fontSize?: string;
fontFamily?: string;
}

View File

@@ -49,7 +49,7 @@ export namespace FontWeight {
export function parse(value: string): FontWeight;
}
interface ParsedFont {
export interface ParsedFont {
fontStyle?: FontStyle;
fontVariant?: string;
fontWeight?: FontWeight,

View File

@@ -28,7 +28,7 @@ import {
messageType as traceMessageType,
} from "../../trace";
import { File, knownFolders, path } from "../../file-system";
import * as applicationCommon from "../../application/application-common";
import * as application from "../../application";
import { profile } from "../../profiling";
import * as kam from "../animation/keyframe-animation";
@@ -330,7 +330,7 @@ export function addTaggedAdditionalCSS(cssText: string, tag?: string | Number):
return changed;
}
const onCssChanged = profile("\"style-scope\".onCssChanged", (args: applicationCommon.CssChangedEventData) => {
const onCssChanged = profile("\"style-scope\".onCssChanged", (args: application.CssChangedEventData) => {
if (args.cssText) {
const parsed = CSSSource.fromSource(args.cssText, applicationKeyframes, args.cssFile).selectors;
if (parsed) {
@@ -342,8 +342,8 @@ const onCssChanged = profile("\"style-scope\".onCssChanged", (args: applicationC
}
});
function onLiveSync(args: applicationCommon.CssChangedEventData): void {
loadCss(applicationCommon.getCssFileName());
function onLiveSync(args: application.CssChangedEventData): void {
loadCss(application.getCssFileName());
}
const loadCss = profile(`"style-scope".loadCss`, (cssModule: string) => {
@@ -363,23 +363,23 @@ const loadCss = profile(`"style-scope".loadCss`, (cssModule: string) => {
}
});
applicationCommon.on("cssChanged", onCssChanged);
applicationCommon.on("livesync", onLiveSync);
application.on("cssChanged", onCssChanged);
application.on("livesync", onLiveSync);
// Call to this method is injected in the application in:
// - no-snapshot - code injected in app.ts by [bundle-config-loader](https://github.com/NativeScript/nativescript-dev-webpack/blob/9b1e34d8ef838006c9b575285c42d2304f5f02b5/bundle-config-loader.ts#L85-L92)
// - with-snapshot - code injected in snapshot bundle by [NativeScriptSnapshotPlugin](https://github.com/NativeScript/nativescript-dev-webpack/blob/48b26f412fd70c19dc0b9c7763e08e9505a0ae11/plugins/NativeScriptSnapshotPlugin/index.js#L48-L56)
// Having the app.css loaded in snapshot provides significant boost in startup (when using the ns-theme ~150 ms). However, because app.css is resolved at build-time,
// when the snapshot is created - there is no way to use file qualifiers or change the name of on app.css
export const loadAppCSS = profile("\"style-scope\".loadAppCSS", (args: applicationCommon.LoadAppCSSEventData) => {
export const loadAppCSS = profile("\"style-scope\".loadAppCSS", (args: application.LoadAppCSSEventData) => {
loadCss(args.cssFile);
applicationCommon.off("loadAppCss", loadAppCSS);
application.off("loadAppCss", loadAppCSS);
});
if (applicationCommon.hasLaunched()) {
loadAppCSS({ eventName: "loadAppCss", object: <any>applicationCommon, cssFile: applicationCommon.getCssFileName() });
if (application.hasLaunched()) {
loadAppCSS({ eventName: "loadAppCss", object: <any>application, cssFile: application.getCssFileName() });
} else {
applicationCommon.on("loadAppCss", loadAppCSS);
application.on("loadAppCss", loadAppCSS);
}
export class CssState {
@@ -790,8 +790,10 @@ export class StyleScope {
}
}
// HACK: This @profile decorator creates a circular dependency
// HACK: because the function parameter type is evaluated with 'typeof'
@profile
public matchSelectors(view: ViewBase): SelectorsMatch<ViewBase> {
public matchSelectors(view: any): SelectorsMatch<ViewBase> { // should be (view: ViewBase): SelectorsMatch<ViewBase>
this.ensureSelectors();
return this._selectors.query(view);