From ff476d983d40afe136bfb4461f8dd20cfc72b21f Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Thu, 31 Jan 2019 18:32:25 +0200 Subject: [PATCH] refactor: rename HmrContext to ModuleContext (#6843) * refactor: rename HmrContext to ModuleContext * refactor(ModuleContext): rename module to path --- tests/app/livesync/livesync-tests.ts | 44 +++++++++---------- .../application/application-common.ts | 4 +- .../application/application.android.ts | 2 +- .../application/application.ios.ts | 2 +- tns-core-modules/module.d.ts | 16 +++---- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/app/livesync/livesync-tests.ts b/tests/app/livesync/livesync-tests.ts index 8ae772203..f1d0a4007 100644 --- a/tests/app/livesync/livesync-tests.ts +++ b/tests/app/livesync/livesync-tests.ts @@ -31,40 +31,40 @@ const pageTemplate = ` `; -export function test_onLiveSync_HmrContext_AppStyle_AppNewCss() { - _test_onLiveSync_HmrContext_AppStyle(appNewCssFileName); +export function test_onLiveSync_ModuleContext_AppStyle_AppNewCss() { + _test_onLiveSync_ModuleContext_AppStyle(appNewCssFileName); } -export function test_onLiveSync_HmrContext_AppStyle_AppNewScss() { - _test_onLiveSync_HmrContext_AppStyle(appNewScssFileName); +export function test_onLiveSync_ModuleContext_AppStyle_AppNewScss() { + _test_onLiveSync_ModuleContext_AppStyle(appNewScssFileName); } -export function test_onLiveSync_HmrContext_ContextUndefined() { - _test_onLiveSync_HmrContext({ type: undefined, module: undefined }); +export function test_onLiveSync_ModuleContext_ContextUndefined() { + _test_onLiveSync_ModuleContext({ type: undefined, path: undefined }); } -export function test_onLiveSync_HmrContext_ModuleUndefined() { - _test_onLiveSync_HmrContext({ type: "script", module: undefined }); +export function test_onLiveSync_ModuleContext_ModuleUndefined() { + _test_onLiveSync_ModuleContext({ type: "script", path: undefined }); } -export function test_onLiveSync_HmrContext_Script_AppJs() { - _test_onLiveSync_HmrContext({ type: "script", module: appJsFileName }); +export function test_onLiveSync_ModuleContext_Script_AppJs() { + _test_onLiveSync_ModuleContext({ type: "script", path: appJsFileName }); } -export function test_onLiveSync_HmrContext_Script_AppTs() { - _test_onLiveSync_HmrContext({ type: "script", module: appTsFileName }); +export function test_onLiveSync_ModuleContext_Script_AppTs() { + _test_onLiveSync_ModuleContext({ type: "script", path: appTsFileName }); } -export function test_onLiveSync_HmrContext_Style_MainPageCss() { - _test_onLiveSync_HmrContext({ type: "style", module: mainPageCssFileName }); +export function test_onLiveSync_ModuleContext_Style_MainPageCss() { + _test_onLiveSync_ModuleContext({ type: "style", path: mainPageCssFileName }); } -export function test_onLiveSync_HmrContext_Markup_MainPageHtml() { - _test_onLiveSync_HmrContext({ type: "markup", module: mainPageHtmlFileName }); +export function test_onLiveSync_ModuleContext_Markup_MainPageHtml() { + _test_onLiveSync_ModuleContext({ type: "markup", path: mainPageHtmlFileName }); } -export function test_onLiveSync_HmrContext_Markup_MainPageXml() { - _test_onLiveSync_HmrContext({ type: "markup", module: mainPageXmlFileName }); +export function test_onLiveSync_ModuleContext_Markup_MainPageXml() { + _test_onLiveSync_ModuleContext({ type: "markup", path: mainPageXmlFileName }); } export function setUpModule() { @@ -76,7 +76,7 @@ export function tearDown() { app.setCssFileName(appCssFileName); } -function _test_onLiveSync_HmrContext_AppStyle(styleFileName: string) { +function _test_onLiveSync_ModuleContext_AppStyle(styleFileName: string) { const pageBeforeNavigation = helper.getCurrentPage(); const page = parse(pageTemplate); @@ -84,7 +84,7 @@ function _test_onLiveSync_HmrContext_AppStyle(styleFileName: string) { app.setCssFileName(styleFileName); const pageBeforeLiveSync = helper.getCurrentPage(); - global.__onLiveSync({ type: "style", module: styleFileName }); + global.__onLiveSync({ type: "style", path: styleFileName }); const pageAfterLiveSync = helper.getCurrentPage(); TKUnit.waitUntilReady(() => pageAfterLiveSync.getViewById("button").style.color.toString() === green.toString()); @@ -101,10 +101,10 @@ function _test_onLiveSync_HmrContext_AppStyle(styleFileName: string) { TKUnit.assertTrue(pageAfterNavigationBack._cssState.isSelectorsLatestVersionApplied(), "Latest selectors version is NOT applied!"); } -function _test_onLiveSync_HmrContext(context: { type, module }) { +function _test_onLiveSync_ModuleContext(context: { type, path }) { const page = parse(pageTemplate); helper.navigateWithHistory(() => page); - global.__onLiveSync({ type: context.type, module: context.module }); + global.__onLiveSync({ type: context.type, path: context.path }); TKUnit.waitUntilReady(() => !!frame.topmost()); const topmostFrame = frame.topmost(); diff --git a/tns-core-modules/application/application-common.ts b/tns-core-modules/application/application-common.ts index 0114d4239..f113902d8 100644 --- a/tns-core-modules/application/application-common.ts +++ b/tns-core-modules/application/application-common.ts @@ -79,7 +79,7 @@ export function setApplication(instance: iOSApplication | AndroidApplication): v app = instance; } -export function livesync(rootView: View, context?: HmrContext) { +export function livesync(rootView: View, context?: ModuleContext) { events.notify({ eventName: "livesync", object: app }); const liveSyncCore = global.__onLiveSyncCore; let reapplyAppCss = false; @@ -88,7 +88,7 @@ export function livesync(rootView: View, context?: HmrContext) { const fullFileName = getCssFileName(); const fileName = fullFileName.substring(0, fullFileName.lastIndexOf(".") + 1); const extensions = ["css", "scss"]; - reapplyAppCss = extensions.some(ext => context.module === fileName.concat(ext)); + reapplyAppCss = extensions.some(ext => context.path === fileName.concat(ext)); } if (reapplyAppCss && rootView) { diff --git a/tns-core-modules/application/application.android.ts b/tns-core-modules/application/application.android.ts index 3b4221dd5..07247a9eb 100644 --- a/tns-core-modules/application/application.android.ts +++ b/tns-core-modules/application/application.android.ts @@ -212,7 +212,7 @@ export function getNativeApplication(): android.app.Application { return nativeApp; } -global.__onLiveSync = function __onLiveSync(context?: HmrContext) { +global.__onLiveSync = function __onLiveSync(context?: ModuleContext) { if (androidApp && androidApp.paused) { return; } diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index f875717db..ed50a80aa 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -373,7 +373,7 @@ function setViewControllerView(view: View): void { } } -global.__onLiveSync = function __onLiveSync(context?: HmrContext) { +global.__onLiveSync = function __onLiveSync(context?: ModuleContext) { if (!started) { return; } diff --git a/tns-core-modules/module.d.ts b/tns-core-modules/module.d.ts index f252e6295..76f015c56 100644 --- a/tns-core-modules/module.d.ts +++ b/tns-core-modules/module.d.ts @@ -51,7 +51,7 @@ declare namespace NodeJS { __native?: any; __inspector?: any; __extends: any; - __onLiveSync: (context?: { type: string, module: string }) => void; + __onLiveSync: (context?: { type: string, path: string }) => void; __onLiveSyncCore: () => void; __onUncaughtError: (error: NativeScriptError) => void; __onDiscardedError: (error: NativeScriptError) => void; @@ -65,25 +65,25 @@ declare function clearTimeout(timeoutId: number): void; declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): number; declare function clearInterval(intervalId: number): void; -declare enum HmrType { +declare enum ModuleType { markup = "markup", script = "script", style = "style" } /** - * Define a context for Hot Module Replacement. + * Define a module context for Hot Module Replacement. */ -interface HmrContext { +interface ModuleContext { /** - * The type of module for replacement. + * The type of the module for replacement. */ - type: HmrType; + type: ModuleType; /** - * The module for replacement. + * The path of the module for replacement. */ - module: string; + path: string; } /**