|
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; |
0 commit comments