mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
Solving previous merge conflict
This commit is contained in:
@ -28,7 +28,6 @@ let imageSource: typeof imageSourceModule;
|
|||||||
function ensureImageSource() {
|
function ensureImageSource() {
|
||||||
if (!imageSource) {
|
if (!imageSource) {
|
||||||
imageSource = require("../../image-source");
|
imageSource = require("../../image-source");
|
||||||
imageSource = require("../../image-source");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,131 +0,0 @@
|
|||||||
// Require globals first so that snapshot takes __extends function.
|
|
||||||
require("../globals");
|
|
||||||
|
|
||||||
import { Observable, EventData } from "../data/observable";
|
|
||||||
import { View } from "../ui/core/view";
|
|
||||||
import {
|
|
||||||
trace as profilingTrace,
|
|
||||||
time,
|
|
||||||
uptime,
|
|
||||||
level as profilingLevel,
|
|
||||||
} from "../profiling";
|
|
||||||
|
|
||||||
const events = new Observable();
|
|
||||||
let launched = false;
|
|
||||||
function setLaunched() {
|
|
||||||
launched = true;
|
|
||||||
events.off("launch", setLaunched);
|
|
||||||
}
|
|
||||||
events.on("launch", setLaunched);
|
|
||||||
|
|
||||||
if (profilingLevel() > 0) {
|
|
||||||
events.on("displayed", () => {
|
|
||||||
const duration = uptime();
|
|
||||||
const end = time();
|
|
||||||
const start = end - duration;
|
|
||||||
profilingTrace(`Displayed in ${duration.toFixed(2)}ms`, start, end);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hasLaunched(): boolean {
|
|
||||||
return launched;
|
|
||||||
}
|
|
||||||
|
|
||||||
export { Observable };
|
|
||||||
|
|
||||||
import {
|
|
||||||
AndroidApplication,
|
|
||||||
CssChangedEventData,
|
|
||||||
iOSApplication,
|
|
||||||
LoadAppCSSEventData,
|
|
||||||
UnhandledErrorEventData,
|
|
||||||
DiscardedErrorEventData,
|
|
||||||
} from "./application";
|
|
||||||
|
|
||||||
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
|
|
||||||
|
|
||||||
export const launchEvent = "launch";
|
|
||||||
export const suspendEvent = "suspend";
|
|
||||||
export const displayedEvent = "displayed";
|
|
||||||
export const resumeEvent = "resume";
|
|
||||||
export const exitEvent = "exit";
|
|
||||||
export const lowMemoryEvent = "lowMemory";
|
|
||||||
export const uncaughtErrorEvent = "uncaughtError";
|
|
||||||
export const discardedErrorEvent = "discardedError";
|
|
||||||
export const orientationChangedEvent = "orientationChanged";
|
|
||||||
|
|
||||||
let cssFile: string = "./app.css";
|
|
||||||
|
|
||||||
let resources: any = {};
|
|
||||||
|
|
||||||
export function getResources() {
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setResources(res: any) {
|
|
||||||
resources = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
export let android = undefined;
|
|
||||||
export let ios = undefined;
|
|
||||||
|
|
||||||
export const on: typeof events.on = events.on.bind(events);
|
|
||||||
export const off: typeof events.off = events.off.bind(events);
|
|
||||||
export const notify: typeof events.notify = events.notify.bind(events);
|
|
||||||
export const hasListeners: typeof events.hasListeners = events.hasListeners.bind(events);
|
|
||||||
|
|
||||||
let app: iOSApplication | AndroidApplication;
|
|
||||||
export function setApplication(instance: iOSApplication | AndroidApplication): void {
|
|
||||||
app = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function livesync(rootView: View, context?: ModuleContext) {
|
|
||||||
events.notify(<EventData>{ eventName: "livesync", object: app });
|
|
||||||
const liveSyncCore = global.__onLiveSyncCore;
|
|
||||||
let reapplyAppStyles = false;
|
|
||||||
|
|
||||||
// ModuleContext is available only for Hot Module Replacement
|
|
||||||
if (context && context.path) {
|
|
||||||
const styleExtensions = ["css", "scss"];
|
|
||||||
const appStylesFullFileName = getCssFileName();
|
|
||||||
const appStylesFileName = appStylesFullFileName.substring(0, appStylesFullFileName.lastIndexOf(".") + 1);
|
|
||||||
reapplyAppStyles = styleExtensions.some(ext => context.path === appStylesFileName.concat(ext));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle application styles
|
|
||||||
if (reapplyAppStyles && rootView) {
|
|
||||||
rootView._onCssStateChange();
|
|
||||||
} else if (liveSyncCore) {
|
|
||||||
liveSyncCore(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setCssFileName(cssFileName: string) {
|
|
||||||
cssFile = cssFileName;
|
|
||||||
events.notify(<CssChangedEventData>{ eventName: "cssChanged", object: app, cssFile: cssFileName });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getCssFileName(): string {
|
|
||||||
return cssFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function loadAppCss(): void {
|
|
||||||
try {
|
|
||||||
events.notify(<LoadAppCSSEventData>{ eventName: "loadAppCss", object: app, cssFile: getCssFileName() });
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(`The file ${getCssFileName()} couldn't be loaded! ` +
|
|
||||||
`You may need to register it inside ./app/vendor.ts.`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addCss(cssText: string): void {
|
|
||||||
events.notify(<CssChangedEventData>{ eventName: "cssChanged", object: app, cssText: cssText });
|
|
||||||
}
|
|
||||||
|
|
||||||
global.__onUncaughtError = function (error: NativeScriptError) {
|
|
||||||
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
|
|
||||||
};
|
|
||||||
|
|
||||||
global.__onDiscardedError = function (error: NativeScriptError) {
|
|
||||||
events.notify(<DiscardedErrorEventData>{ eventName: discardedErrorEvent, object: app, error: error });
|
|
||||||
};
|
|
@ -1,47 +0,0 @@
|
|||||||
if (global.TNS_WEBPACK) {
|
|
||||||
require("globals");
|
|
||||||
|
|
||||||
// Register "dynamically" loaded module that need to be resolved by the
|
|
||||||
// XML/component builders.
|
|
||||||
|
|
||||||
global.registerModule("text/formatted-string", () => require("./text/formatted-string"));
|
|
||||||
global.registerModule("text/span", () => require("./text/span"));
|
|
||||||
global.registerModule("ui/action-bar", () => require("./ui/action-bar"));
|
|
||||||
global.registerModule("ui/activity-indicator", () => require("./ui/activity-indicator"));
|
|
||||||
global.registerModule("ui/border", () => require("./ui/border"));
|
|
||||||
global.registerModule("ui/bottom-navigation", () => require("./ui/bottom-navigation"));
|
|
||||||
global.registerModule("ui/button", () => require("./ui/button"));
|
|
||||||
global.registerModule("ui/content-view", () => require("./ui/content-view"));
|
|
||||||
global.registerModule("ui/date-picker", () => require("./ui/date-picker"));
|
|
||||||
global.registerModule("ui/frame", () => require("./ui/frame"));
|
|
||||||
global.registerModule("ui/html-view", () => require("./ui/html-view"));
|
|
||||||
global.registerModule("ui/image", () => require("./ui/image"));
|
|
||||||
global.registerModule("ui/label", () => require("./ui/label"));
|
|
||||||
global.registerModule("ui/layouts/absolute-layout", () => require("./ui/layouts/absolute-layout"));
|
|
||||||
global.registerModule("ui/layouts/dock-layout", () => require("./ui/layouts/dock-layout"));
|
|
||||||
global.registerModule("ui/layouts/grid-layout", () => require("./ui/layouts/grid-layout"));
|
|
||||||
global.registerModule("ui/layouts/stack-layout", () => require("./ui/layouts/stack-layout"));
|
|
||||||
global.registerModule("ui/layouts/flexbox-layout", () => require("./ui/layouts/flexbox-layout"));
|
|
||||||
global.registerModule("ui/layouts/wrap-layout", () => require("./ui/layouts/wrap-layout"));
|
|
||||||
global.registerModule("ui/list-picker", () => require("./ui/list-picker"));
|
|
||||||
global.registerModule("ui/page", () => require("./ui/page"));
|
|
||||||
global.registerModule("ui/placeholder", () => require("./ui/placeholder"));
|
|
||||||
global.registerModule("ui/progress", () => require("./ui/progress"));
|
|
||||||
global.registerModule("ui/proxy-view-container", () => require("./ui/proxy-view-container"));
|
|
||||||
global.registerModule("ui/repeater", () => require("./ui/repeater"));
|
|
||||||
global.registerModule("ui/scroll-view", () => require("./ui/scroll-view"));
|
|
||||||
global.registerModule("ui/search-bar", () => require("./ui/search-bar"));
|
|
||||||
global.registerModule("ui/segmented-bar", () => require("./ui/segmented-bar"));
|
|
||||||
global.registerModule("ui/slider", () => require("./ui/slider"));
|
|
||||||
global.registerModule("ui/switch", () => require("./ui/switch"));
|
|
||||||
global.registerModule("ui/tab-view", () => require("./ui/tab-view"));
|
|
||||||
global.registerModule("ui/tab-navigation-base/tab-strip", () => require("./ui/tab-navigation-base/tab-strip"));
|
|
||||||
global.registerModule("ui/tab-navigation-base/tab-strip-item", () => require("./ui/tab-navigation-base/tab-strip-item"));
|
|
||||||
global.registerModule("ui/tab-navigation-base/tab-content-item", () => require("./ui/tab-navigation-base/tab-content-item"));
|
|
||||||
global.registerModule("ui/tabs", () => require("./ui/tabs"));
|
|
||||||
global.registerModule("ui/web-view", () => require("./ui/web-view"));
|
|
||||||
global.registerModule("ui/text-field", () => require("./ui/text-field"));
|
|
||||||
global.registerModule("ui/text-view", () => require("./ui/text-view"));
|
|
||||||
global.registerModule("ui/time-picker", () => require("./ui/time-picker"));
|
|
||||||
global.registerModule("ui/list-view", () => require("./ui/list-view"));
|
|
||||||
}
|
|
@ -1,261 +0,0 @@
|
|||||||
// Required by TypeScript compiler
|
|
||||||
require("./ts-helpers");
|
|
||||||
|
|
||||||
// This method iterates all the keys in the source exports object and copies them to the destination exports one.
|
|
||||||
// Note: the method will not check for naming collisions and will override any already existing entries in the destination exports.
|
|
||||||
global.moduleMerge = function (sourceExports: any, destExports: any) {
|
|
||||||
for (let key in sourceExports) {
|
|
||||||
destExports[key] = sourceExports[key];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
import * as timerModule from "../timer";
|
|
||||||
import * as dialogsModule from "../ui/dialogs";
|
|
||||||
|
|
||||||
type ModuleLoader = (name?: string) => any;
|
|
||||||
const modules: Map<string, ModuleLoader> = new Map<string, ModuleLoader>();
|
|
||||||
|
|
||||||
(<any>global).moduleResolvers = [global.require];
|
|
||||||
|
|
||||||
global.registerModule = function (name: string, loader: ModuleLoader): void {
|
|
||||||
// console.log("[global.registerModule]", name);
|
|
||||||
modules.set(name, loader);
|
|
||||||
};
|
|
||||||
|
|
||||||
global._unregisterModule = function (name: string): void {
|
|
||||||
// console.log("[global._unregisterModule]", name);
|
|
||||||
modules.delete(name);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface Context {
|
|
||||||
keys(): string[];
|
|
||||||
(key: string): any;
|
|
||||||
}
|
|
||||||
interface ExtensionMap {
|
|
||||||
[originalFileExtension: string]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultExtensionMap = {
|
|
||||||
".js": ".js",
|
|
||||||
".ts": ".js",
|
|
||||||
".css": ".css",
|
|
||||||
".scss": ".css",
|
|
||||||
".less": ".css",
|
|
||||||
".sass": ".css",
|
|
||||||
".xml": ".xml"
|
|
||||||
};
|
|
||||||
|
|
||||||
global.registerWebpackModules = function registerWebpackModules(context: Context, extensionMap: ExtensionMap = {}) {
|
|
||||||
context.keys().forEach(key => {
|
|
||||||
const extDotIndex = key.lastIndexOf(".");
|
|
||||||
const base = key.substr(0, extDotIndex);
|
|
||||||
const originalExt = key.substr(extDotIndex);
|
|
||||||
const registerExt = extensionMap[originalExt] || defaultExtensionMap[originalExt] || originalExt;
|
|
||||||
|
|
||||||
// We prefer source files for webpack scenarios before compilation leftovers,
|
|
||||||
// e. g. if we get a .js and .ts for the same module, the .js is probably the compiled version of the .ts file,
|
|
||||||
// so we register the .ts with higher priority, similar is the case with us preferring the .scss to .css
|
|
||||||
const isSourceFile = originalExt !== registerExt;
|
|
||||||
|
|
||||||
const registerName = base + registerExt;
|
|
||||||
if (registerName.startsWith("./") && registerName.endsWith(".js")) {
|
|
||||||
const jsNickNames = [
|
|
||||||
// This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc);
|
|
||||||
registerName.substr(2, registerName.length - 5),
|
|
||||||
// This is for supporting module names like "./main/main-page"
|
|
||||||
registerName.substr(0, registerName.length - 3),
|
|
||||||
// This is for supporting module names like "main/main-page.js"
|
|
||||||
registerName.substr(2),
|
|
||||||
];
|
|
||||||
|
|
||||||
jsNickNames.forEach(jsNickName => {
|
|
||||||
if (isSourceFile || !global.moduleExists(jsNickName)) {
|
|
||||||
global.registerModule(jsNickName, () => context(key));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (registerName.startsWith("./")) {
|
|
||||||
const moduleNickNames = [
|
|
||||||
// This is for supporting module names like "main/main-page.xml"
|
|
||||||
registerName.substr(2),
|
|
||||||
];
|
|
||||||
|
|
||||||
moduleNickNames.forEach(moduleNickName => {
|
|
||||||
if (!global.moduleExists(moduleNickName)) {
|
|
||||||
global.registerModule(moduleNickName, () => context(key));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSourceFile || !global.moduleExists(registerName)) {
|
|
||||||
global.registerModule(registerName, () => context(key));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
global.moduleExists = function (name: string): boolean {
|
|
||||||
return modules.has(name);
|
|
||||||
};
|
|
||||||
|
|
||||||
global.loadModule = function (name: string): any {
|
|
||||||
const loader = modules.get(name);
|
|
||||||
if (loader) {
|
|
||||||
return loader(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let resolver of (<any>global).moduleResolvers) {
|
|
||||||
const result = resolver(name);
|
|
||||||
if (result) {
|
|
||||||
modules.set(name, () => result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
global.getRegisteredModules = function (): string[] {
|
|
||||||
return Array.from(modules.keys());
|
|
||||||
};
|
|
||||||
|
|
||||||
global.zonedCallback = function (callback: Function): Function {
|
|
||||||
if ((<any>global).zone) {
|
|
||||||
// Zone v0.5.* style callback wrapping
|
|
||||||
return (<any>global).zone.bind(callback);
|
|
||||||
}
|
|
||||||
if ((<any>global).Zone) {
|
|
||||||
// Zone v0.6.* style callback wrapping
|
|
||||||
return (<any>global).Zone.current.wrap(callback);
|
|
||||||
} else {
|
|
||||||
return callback;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
global.registerModule("timer", () => require("../timer"));
|
|
||||||
global.registerModule("ui/dialogs", () => require("../ui/dialogs"));
|
|
||||||
global.registerModule("xhr", () => require("../xhr"));
|
|
||||||
global.registerModule("fetch", () => require("../fetch"));
|
|
||||||
|
|
||||||
(<any>global).System = {
|
|
||||||
import(path) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
try {
|
|
||||||
resolve(global.require(path));
|
|
||||||
} catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function registerOnGlobalContext(name: string, module: string): void {
|
|
||||||
Object.defineProperty(global, name, {
|
|
||||||
get: function () {
|
|
||||||
// We do not need to cache require() call since it is already cached in the runtime.
|
|
||||||
let m = global.loadModule(module);
|
|
||||||
|
|
||||||
// Redefine the property to make sure the above code is executed only once.
|
|
||||||
let resolvedValue = m[name];
|
|
||||||
Object.defineProperty(global, name, { value: resolvedValue, configurable: true, writable: true });
|
|
||||||
|
|
||||||
return resolvedValue;
|
|
||||||
},
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let snapshotGlobals;
|
|
||||||
export function install() {
|
|
||||||
if ((<any>global).__snapshot || (<any>global).__snapshotEnabled) {
|
|
||||||
if (!snapshotGlobals) {
|
|
||||||
// require in snapshot mode is cheap
|
|
||||||
const timer: typeof timerModule = require("../timer");
|
|
||||||
const dialogs: typeof dialogsModule = require("../ui/dialogs");
|
|
||||||
const xhr = require("../xhr");
|
|
||||||
const fetch = require("../fetch");
|
|
||||||
|
|
||||||
snapshotGlobals = snapshotGlobals || {
|
|
||||||
setTimeout: timer.setTimeout,
|
|
||||||
clearTimeout: timer.clearTimeout,
|
|
||||||
setInterval: timer.setInterval,
|
|
||||||
clearInterval: timer.clearInterval,
|
|
||||||
|
|
||||||
alert: dialogs.alert,
|
|
||||||
confirm: dialogs.confirm,
|
|
||||||
prompt: dialogs.prompt,
|
|
||||||
login: dialogs.login,
|
|
||||||
action: dialogs.action,
|
|
||||||
|
|
||||||
XMLHttpRequest: xhr.XMLHttpRequest,
|
|
||||||
FormData: xhr.FormData,
|
|
||||||
|
|
||||||
fetch: fetch.fetch,
|
|
||||||
Headers: fetch.Headers,
|
|
||||||
Request: fetch.Request,
|
|
||||||
Response: fetch.Response,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const consoleModule = require("../console").Console;
|
|
||||||
// Object.assign call will fire an error when trying to write to a read-only property of an object, such as 'console'
|
|
||||||
global.console = global.console || new consoleModule();
|
|
||||||
Object.assign(global, snapshotGlobals);
|
|
||||||
} else {
|
|
||||||
registerOnGlobalContext("setTimeout", "timer");
|
|
||||||
registerOnGlobalContext("clearTimeout", "timer");
|
|
||||||
registerOnGlobalContext("setInterval", "timer");
|
|
||||||
registerOnGlobalContext("clearInterval", "timer");
|
|
||||||
|
|
||||||
registerOnGlobalContext("alert", "ui/dialogs");
|
|
||||||
registerOnGlobalContext("confirm", "ui/dialogs");
|
|
||||||
registerOnGlobalContext("prompt", "ui/dialogs");
|
|
||||||
registerOnGlobalContext("login", "ui/dialogs");
|
|
||||||
registerOnGlobalContext("action", "ui/dialogs");
|
|
||||||
|
|
||||||
registerOnGlobalContext("XMLHttpRequest", "xhr");
|
|
||||||
registerOnGlobalContext("FormData", "xhr");
|
|
||||||
|
|
||||||
registerOnGlobalContext("fetch", "fetch");
|
|
||||||
registerOnGlobalContext("Headers", "fetch");
|
|
||||||
registerOnGlobalContext("Request", "fetch");
|
|
||||||
registerOnGlobalContext("Response", "fetch");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
install();
|
|
||||||
|
|
||||||
export function Deprecated(target: Object, key?: string | symbol, descriptor?: any) {
|
|
||||||
if (descriptor) {
|
|
||||||
const originalMethod = descriptor.value;
|
|
||||||
|
|
||||||
descriptor.value = function (...args: any[]) {
|
|
||||||
console.log(`${key.toString()} is deprecated`);
|
|
||||||
|
|
||||||
return originalMethod.apply(this, args);
|
|
||||||
};
|
|
||||||
|
|
||||||
return descriptor;
|
|
||||||
} else {
|
|
||||||
console.log(`${(target && (<any>target).name || target)} is deprecated`);
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global.Deprecated = Deprecated;
|
|
||||||
|
|
||||||
export function Experimental(target: Object, key?: string | symbol, descriptor?: any) {
|
|
||||||
if (descriptor) {
|
|
||||||
const originalMethod = descriptor.value;
|
|
||||||
|
|
||||||
descriptor.value = function (...args: any[]) {
|
|
||||||
console.log(`${key.toString()} is experimental`);
|
|
||||||
|
|
||||||
return originalMethod.apply(this, args);
|
|
||||||
};
|
|
||||||
|
|
||||||
return descriptor;
|
|
||||||
} else {
|
|
||||||
console.log(`${(target && (<any>target).name || target)} is experimental`);
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global.Experimental = Experimental;
|
|
Reference in New Issue
Block a user