| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 92238a9 commit 0ee0b67
15 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + // Required by TypeScript compiler | ||
| 2 | + import "../ts-helpers"; | ||
| 3 | + | ||
| 4 | + import "../register-module-helpers"; | ||
| 5 | + | ||
| 6 | + // This method iterates all the keys in the source exports object and copies them to the destination exports one. | ||
| 7 | + // Note: the method will not check for naming collisions and will override any already existing entries in the destination exports. | ||
| 8 | + global.moduleMerge = function (sourceExports: any, destExports: any) { | ||
| 9 | + for (let key in sourceExports) { | ||
| 10 | + destExports[key] = sourceExports[key]; | ||
| 11 | + } | ||
| 12 | + }; | ||
| 13 | + | ||
| 14 | + global.zonedCallback = function (callback: Function): Function { | ||
| 15 | + if ((<any>global).zone) { | ||
| 16 | + // Zone v0.5.* style callback wrapping | ||
| 17 | + return (<any>global).zone.bind(callback); | ||
| 18 | + } | ||
| 19 | + if ((<any>global).Zone) { | ||
| 20 | + // Zone v0.6.* style callback wrapping | ||
| 21 | + return (<any>global).Zone.current.wrap(callback); | ||
| 22 | + } else { | ||
| 23 | + return callback; | ||
| 24 | + } | ||
| 25 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "name" : "core", | ||
| 3 | + "main" : "globals-core", | ||
| 4 | + "nativescript": {} | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,39 @@ | |||
| 1 | + export function Deprecated(target: Object, key?: string | symbol, descriptor?: any) { | ||
| 2 | + if (descriptor) { | ||
| 3 | + const originalMethod = descriptor.value; | ||
| 4 | + | ||
| 5 | + descriptor.value = function (...args: any[]) { | ||
| 6 | + console.log(`${key.toString()} is deprecated`); | ||
| 7 | + | ||
| 8 | + return originalMethod.apply(this, args); | ||
| 9 | + }; | ||
| 10 | + | ||
| 11 | + return descriptor; | ||
| 12 | + } else { | ||
| 13 | + console.log(`${(target && (<any>target).name || target)} is deprecated`); | ||
| 14 | + | ||
| 15 | + return target; | ||
| 16 | + } | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + global.Deprecated = Deprecated; | ||
| 20 | + | ||
| 21 | + export function Experimental(target: Object, key?: string | symbol, descriptor?: any) { | ||
| 22 | + if (descriptor) { | ||
| 23 | + const originalMethod = descriptor.value; | ||
| 24 | + | ||
| 25 | + descriptor.value = function (...args: any[]) { | ||
| 26 | + console.log(`${key.toString()} is experimental`); | ||
| 27 | + | ||
| 28 | + return originalMethod.apply(this, args); | ||
| 29 | + }; | ||
| 30 | + | ||
| 31 | + return descriptor; | ||
| 32 | + } else { | ||
| 33 | + console.log(`${(target && (<any>target).name || target)} is experimental`); | ||
| 34 | + | ||
| 35 | + return target; | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + global.Experimental = Experimental; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,159 +1,15 @@ | |||
| 1 | - // Required by TypeScript compiler | ||
| 2 | - import "./ts-helpers"; | ||
| 1 | + import "./core"; | ||
| 3 | 2 | ||
| 4 | - import "./register-module-helpers"; | ||
| 3 | + import "./polyfills/timers"; | ||
| 4 | + import "./polyfills/dialogs"; | ||
| 5 | + import "./polyfills/xhr"; | ||
| 6 | + import "./polyfills/fetch"; | ||
| 5 | 7 | ||
| 6 | - // This method iterates all the keys in the source exports object and copies them to the destination exports one. | ||
| 7 | - // Note: the method will not check for naming collisions and will override any already existing entries in the destination exports. | ||
| 8 | - global.moduleMerge = function (sourceExports: any, destExports: any) { | ||
| 9 | - for (let key in sourceExports) { | ||
| 10 | - destExports[key] = sourceExports[key]; | ||
| 11 | - } | ||
| 12 | - }; | ||
| 8 | + import "./decorators"; | ||
| 13 | 9 | ||
| 14 | - import * as timerModule from "../timer"; | ||
| 15 | - import * as dialogsModule from "../ui/dialogs"; | ||
| 16 | - | ||
| 17 | - global.zonedCallback = function (callback: Function): Function { | ||
| 18 | - if ((<any>global).zone) { | ||
| 19 | - // Zone v0.5.* style callback wrapping | ||
| 20 | - return (<any>global).zone.bind(callback); | ||
| 21 | - } | ||
| 22 | - if ((<any>global).Zone) { | ||
| 23 | - // Zone v0.6.* style callback wrapping | ||
| 24 | - return (<any>global).Zone.current.wrap(callback); | ||
| 25 | - } else { | ||
| 26 | - return callback; | ||
| 27 | - } | ||
| 28 | - }; | ||
| 29 | - | ||
| 30 | - global.registerModule("timer", () => require("../timer")); | ||
| 31 | - global.registerModule("ui/dialogs", () => require("../ui/dialogs")); | ||
| 32 | - global.registerModule("xhr", () => require("../xhr")); | ||
| 33 | - global.registerModule("fetch", () => require("../fetch")); | ||
| 34 | - | ||
| 35 | - (<any>global).System = { | ||
| 36 | - import(path) { | ||
| 37 | - return new Promise((resolve, reject) => { | ||
| 38 | - try { | ||
| 39 | - resolve(global.require(path)); | ||
| 40 | - } catch (e) { | ||
| 41 | - reject(e); | ||
| 42 | - } | ||
| 43 | - }); | ||
| 44 | - } | ||
| 45 | - }; | ||
| 46 | - | ||
| 47 | - function registerOnGlobalContext(name: string, module: string): void { | ||
| 48 | - Object.defineProperty(global, name, { | ||
| 49 | - get: function () { | ||
| 50 | - // We do not need to cache require() call since it is already cached in the runtime. | ||
| 51 | - let m = global.loadModule(module); | ||
| 52 | - | ||
| 53 | - // Redefine the property to make sure the above code is executed only once. | ||
| 54 | - let resolvedValue = m[name]; | ||
| 55 | - Object.defineProperty(global, name, { value: resolvedValue, configurable: true, writable: true }); | ||
| 56 | - | ||
| 57 | - return resolvedValue; | ||
| 58 | - }, | ||
| 59 | - configurable: true | ||
| 60 | - }); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - let snapshotGlobals; | ||
| 64 | - export function install() { | ||
| 65 | - if ((<any>global).__snapshot || (<any>global).__snapshotEnabled) { | ||
| 66 | - if (!snapshotGlobals) { | ||
| 67 | - // require in snapshot mode is cheap | ||
| 68 | - const timer: typeof timerModule = require("../timer"); | ||
| 69 | - const dialogs: typeof dialogsModule = require("../ui/dialogs"); | ||
| 70 | - const xhr = require("../xhr"); | ||
| 71 | - const fetch = require("../fetch"); | ||
| 72 | - | ||
| 73 | - snapshotGlobals = snapshotGlobals || { | ||
| 74 | - setTimeout: timer.setTimeout, | ||
| 75 | - clearTimeout: timer.clearTimeout, | ||
| 76 | - setInterval: timer.setInterval, | ||
| 77 | - clearInterval: timer.clearInterval, | ||
| 78 | - | ||
| 79 | - alert: dialogs.alert, | ||
| 80 | - confirm: dialogs.confirm, | ||
| 81 | - prompt: dialogs.prompt, | ||
| 82 | - login: dialogs.login, | ||
| 83 | - action: dialogs.action, | ||
| 84 | - | ||
| 85 | - XMLHttpRequest: xhr.XMLHttpRequest, | ||
| 86 | - FormData: xhr.FormData, | ||
| 87 | - | ||
| 88 | - fetch: fetch.fetch, | ||
| 89 | - Headers: fetch.Headers, | ||
| 90 | - Request: fetch.Request, | ||
| 91 | - Response: fetch.Response, | ||
| 92 | - }; | ||
| 93 | - } | ||
| 94 | - const consoleModule = require("../console").Console; | ||
| 95 | - // Object.assign call will fire an error when trying to write to a read-only property of an object, such as 'console' | ||
| 96 | - global.console = global.console || new consoleModule(); | ||
| 97 | - Object.assign(global, snapshotGlobals); | ||
| 98 | - } else { | ||
| 99 | - registerOnGlobalContext("setTimeout", "timer"); | ||
| 100 | - registerOnGlobalContext("clearTimeout", "timer"); | ||
| 101 | - registerOnGlobalContext("setInterval", "timer"); | ||
| 102 | - registerOnGlobalContext("clearInterval", "timer"); | ||
| 103 | - | ||
| 104 | - registerOnGlobalContext("alert", "ui/dialogs"); | ||
| 105 | - registerOnGlobalContext("confirm", "ui/dialogs"); | ||
| 106 | - registerOnGlobalContext("prompt", "ui/dialogs"); | ||
| 107 | - registerOnGlobalContext("login", "ui/dialogs"); | ||
| 108 | - registerOnGlobalContext("action", "ui/dialogs"); | ||
| 109 | - | ||
| 110 | - registerOnGlobalContext("XMLHttpRequest", "xhr"); | ||
| 111 | - registerOnGlobalContext("FormData", "xhr"); | ||
| 112 | - | ||
| 113 | - registerOnGlobalContext("fetch", "fetch"); | ||
| 114 | - registerOnGlobalContext("Headers", "fetch"); | ||
| 115 | - registerOnGlobalContext("Request", "fetch"); | ||
| 116 | - registerOnGlobalContext("Response", "fetch"); | ||
| 117 | - } | ||
| 10 | + // This is probably not needed any more | ||
| 11 | + if ((<any>global).__snapshot || (<any>global).__snapshotEnabled) { | ||
| 12 | + // Object.assign call will fire an error when trying to write to a read-only property of an object, such as 'console' | ||
| 13 | + const consoleModule = require("console").Console; | ||
| 14 | + global.console = global.console || new consoleModule(); | ||
| 118 | 15 | } | |
| 119 | - install(); | ||
| 120 | - | ||
| 121 | - export function Deprecated(target: Object, key?: string | symbol, descriptor?: any) { | ||
| 122 | - if (descriptor) { | ||
| 123 | - const originalMethod = descriptor.value; | ||
| 124 | - | ||
| 125 | - descriptor.value = function (...args: any[]) { | ||
| 126 | - console.log(`${key.toString()} is deprecated`); | ||
| 127 | - | ||
| 128 | - return originalMethod.apply(this, args); | ||
| 129 | - }; | ||
| 130 | - | ||
| 131 | - return descriptor; | ||
| 132 | - } else { | ||
| 133 | - console.log(`${(target && (<any>target).name || target)} is deprecated`); | ||
| 134 | - | ||
| 135 | - return target; | ||
| 136 | - } | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - global.Deprecated = Deprecated; | ||
| 140 | - | ||
| 141 | - export function Experimental(target: Object, key?: string | symbol, descriptor?: any) { | ||
| 142 | - if (descriptor) { | ||
| 143 | - const originalMethod = descriptor.value; | ||
| 144 | - | ||
| 145 | - descriptor.value = function (...args: any[]) { | ||
| 146 | - console.log(`${key.toString()} is experimental`); | ||
| 147 | - | ||
| 148 | - return originalMethod.apply(this, args); | ||
| 149 | - }; | ||
| 150 | - | ||
| 151 | - return descriptor; | ||
| 152 | - } else { | ||
| 153 | - console.log(`${(target && (<any>target).name || target)} is experimental`); | ||
| 154 | - | ||
| 155 | - return target; | ||
| 156 | - } | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - global.Experimental = Experimental; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + import "../../core"; | ||
| 2 | + import { installPolyfills } from "../polyfill-helpers"; | ||
| 3 | + | ||
| 4 | + global.registerModule("tns-core-modules/ui/dialogs", () => require("../../../ui/dialogs")); | ||
| 5 | + | ||
| 6 | + installPolyfills("tns-core-modules/ui/dialogs", ["alert", "confirm", "prompt", "login", "action"]); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "name" : "dialogs", | ||
| 3 | + "main" : "dialogs", | ||
| 4 | + "nativescript": {} | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + import "../../core"; | ||
| 2 | + import "../../polyfills/xhr"; | ||
| 3 | + | ||
| 4 | + import { installPolyfills } from "../polyfill-helpers"; | ||
| 5 | + | ||
| 6 | + global.registerModule("fetch", () => require("../../../fetch")); | ||
| 7 | + | ||
| 8 | + installPolyfills("fetch", ["fetch", "Headers", "Request", "Response"]); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "name" : "fetch", | ||
| 3 | + "main" : "fetch", | ||
| 4 | + "nativescript": {} | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "name" : "polyfill-helpers", | ||
| 3 | + "main" : "polyfill-helpers", | ||
| 4 | + "nativescript": {} | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + import "../../core"; | ||
| 2 | + | ||
| 3 | + function registerOnGlobalContext(moduleName: string, exportName: string): void { | ||
| 4 | + Object.defineProperty(global, exportName, { | ||
| 5 | + get: function () { | ||
| 6 | + // We do not need to cache require() call since it is already cached in the runtime. | ||
| 7 | + let m = global.loadModule(moduleName); | ||
| 8 | + | ||
| 9 | + // Redefine the property to make sure the above code is executed only once. | ||
| 10 | + let resolvedValue = m[exportName]; | ||
| 11 | + Object.defineProperty(global, exportName, { value: resolvedValue, configurable: true, writable: true }); | ||
| 12 | + | ||
| 13 | + return resolvedValue; | ||
| 14 | + }, | ||
| 15 | + configurable: true | ||
| 16 | + }); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + export function installPolyfills(moduleName: string, exportNames: string[]) { | ||
| 20 | + if ((<any>global).__snapshot || (<any>global).__snapshotEnabled) { | ||
| 21 | + const loadedModule = global.loadModule(moduleName); | ||
| 22 | + exportNames.forEach(exportName => global[exportName] = loadedModule[exportName]); | ||
| 23 | + } else { | ||
| 24 | + exportNames.forEach(exportName => registerOnGlobalContext(moduleName, exportName)); | ||
| 25 | + } | ||
| 26 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments