@aurelia/platform
Advanced tools
Comparing version 0.8.0-dev.202010270611 to 0.8.0-dev.202011010944
@@ -0,1 +1,2 @@ | ||
const lookup = new Map(); | ||
function notImplemented(name) { | ||
@@ -8,3 +9,3 @@ return function notImplemented() { | ||
constructor(g, overrides = {}) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
this.macroTaskRequested = false; | ||
@@ -22,8 +23,7 @@ this.macroTaskHandle = -1; | ||
this.clearTimeout = 'clearTimeout' in overrides ? overrides.clearTimeout : (_d = (_c = g.clearTimeout) === null || _c === void 0 ? void 0 : _c.bind(g)) !== null && _d !== void 0 ? _d : notImplemented('clearTimeout'); | ||
this.fetch = 'fetch' in overrides ? overrides.fetch : (_f = (_e = g.fetch) === null || _e === void 0 ? void 0 : _e.bind(g)) !== null && _f !== void 0 ? _f : notImplemented('fetch'); | ||
this.queueMicrotask = 'queueMicrotask' in overrides ? overrides.queueMicrotask : (_h = (_g = g.queueMicrotask) === null || _g === void 0 ? void 0 : _g.bind(g)) !== null && _h !== void 0 ? _h : notImplemented('queueMicrotask'); | ||
this.setInterval = 'setInterval' in overrides ? overrides.setInterval : (_k = (_j = g.setInterval) === null || _j === void 0 ? void 0 : _j.bind(g)) !== null && _k !== void 0 ? _k : notImplemented('setInterval'); | ||
this.setTimeout = 'setTimeout' in overrides ? overrides.setTimeout : (_m = (_l = g.setTimeout) === null || _l === void 0 ? void 0 : _l.bind(g)) !== null && _m !== void 0 ? _m : notImplemented('setTimeout'); | ||
this.queueMicrotask = 'queueMicrotask' in overrides ? overrides.queueMicrotask : (_f = (_e = g.queueMicrotask) === null || _e === void 0 ? void 0 : _e.bind(g)) !== null && _f !== void 0 ? _f : notImplemented('queueMicrotask'); | ||
this.setInterval = 'setInterval' in overrides ? overrides.setInterval : (_h = (_g = g.setInterval) === null || _g === void 0 ? void 0 : _g.bind(g)) !== null && _h !== void 0 ? _h : notImplemented('setInterval'); | ||
this.setTimeout = 'setTimeout' in overrides ? overrides.setTimeout : (_k = (_j = g.setTimeout) === null || _j === void 0 ? void 0 : _j.bind(g)) !== null && _k !== void 0 ? _k : notImplemented('setTimeout'); | ||
this.console = 'console' in overrides ? overrides.console : g.console; | ||
this.performanceNow = 'performanceNow' in overrides ? overrides.performanceNow : (_q = (_p = (_o = g.performance) === null || _o === void 0 ? void 0 : _o.now) === null || _p === void 0 ? void 0 : _p.bind(g.performance)) !== null && _q !== void 0 ? _q : notImplemented('performance.now'); | ||
this.performanceNow = 'performanceNow' in overrides ? overrides.performanceNow : (_o = (_m = (_l = g.performance) === null || _l === void 0 ? void 0 : _l.now) === null || _m === void 0 ? void 0 : _m.bind(g.performance)) !== null && _o !== void 0 ? _o : notImplemented('performance.now'); | ||
this.flushMacroTask = this.flushMacroTask.bind(this); | ||
@@ -33,2 +33,12 @@ this.macroTaskQueue = new TaskQueue(this, this.requestMacroTask.bind(this), this.cancelMacroTask.bind(this)); | ||
} | ||
static getOrCreate(g, overrides = {}) { | ||
let platform = lookup.get(g); | ||
if (platform === void 0) { | ||
lookup.set(g, platform = new Platform(g, overrides)); | ||
} | ||
return platform; | ||
} | ||
static set(g, platform) { | ||
lookup.set(g, platform); | ||
} | ||
requestMacroTask() { | ||
@@ -35,0 +45,0 @@ this.macroTaskRequested = true; |
@@ -1,3 +0,2 @@ | ||
declare type GlobalThisOrWindowOrWorkerGlobalScope = Pick<typeof globalThis, Exclude<keyof typeof globalThis, Exclude<keyof Window, keyof WindowOrWorkerGlobalScope>>>; | ||
export declare class Platform<TGlobal extends GlobalThisOrWindowOrWorkerGlobalScope = GlobalThisOrWindowOrWorkerGlobalScope> { | ||
export declare class Platform<TGlobal extends typeof globalThis = typeof globalThis> { | ||
readonly globalThis: TGlobal; | ||
@@ -12,3 +11,2 @@ readonly decodeURI: TGlobal['decodeURI']; | ||
readonly clearTimeout: TGlobal['clearTimeout']; | ||
readonly fetch: TGlobal['fetch']; | ||
readonly queueMicrotask: TGlobal['queueMicrotask']; | ||
@@ -18,5 +16,7 @@ readonly setInterval: TGlobal['setInterval']; | ||
readonly console: TGlobal['console']; | ||
readonly performanceNow: TGlobal['performance']['now']; | ||
readonly performanceNow: () => number; | ||
readonly macroTaskQueue: TaskQueue; | ||
constructor(g: TGlobal, overrides?: Partial<Exclude<Platform, 'globalThis'>>); | ||
static getOrCreate<TGlobal extends typeof globalThis = typeof globalThis>(g: TGlobal, overrides?: Partial<Exclude<Platform, 'globalThis'>>): Platform<TGlobal>; | ||
static set(g: typeof globalThis, platform: Platform): void; | ||
protected macroTaskRequested: boolean; | ||
@@ -23,0 +23,0 @@ protected macroTaskHandle: number; |
@@ -13,2 +13,3 @@ (function (factory) { | ||
exports.TaskQueuePriority = exports.Task = exports.TaskStatus = exports.TaskAbortError = exports.TaskQueue = exports.Platform = void 0; | ||
const lookup = new Map(); | ||
function notImplemented(name) { | ||
@@ -21,3 +22,3 @@ return function notImplemented() { | ||
constructor(g, overrides = {}) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; | ||
this.macroTaskRequested = false; | ||
@@ -35,8 +36,7 @@ this.macroTaskHandle = -1; | ||
this.clearTimeout = 'clearTimeout' in overrides ? overrides.clearTimeout : (_d = (_c = g.clearTimeout) === null || _c === void 0 ? void 0 : _c.bind(g)) !== null && _d !== void 0 ? _d : notImplemented('clearTimeout'); | ||
this.fetch = 'fetch' in overrides ? overrides.fetch : (_f = (_e = g.fetch) === null || _e === void 0 ? void 0 : _e.bind(g)) !== null && _f !== void 0 ? _f : notImplemented('fetch'); | ||
this.queueMicrotask = 'queueMicrotask' in overrides ? overrides.queueMicrotask : (_h = (_g = g.queueMicrotask) === null || _g === void 0 ? void 0 : _g.bind(g)) !== null && _h !== void 0 ? _h : notImplemented('queueMicrotask'); | ||
this.setInterval = 'setInterval' in overrides ? overrides.setInterval : (_k = (_j = g.setInterval) === null || _j === void 0 ? void 0 : _j.bind(g)) !== null && _k !== void 0 ? _k : notImplemented('setInterval'); | ||
this.setTimeout = 'setTimeout' in overrides ? overrides.setTimeout : (_m = (_l = g.setTimeout) === null || _l === void 0 ? void 0 : _l.bind(g)) !== null && _m !== void 0 ? _m : notImplemented('setTimeout'); | ||
this.queueMicrotask = 'queueMicrotask' in overrides ? overrides.queueMicrotask : (_f = (_e = g.queueMicrotask) === null || _e === void 0 ? void 0 : _e.bind(g)) !== null && _f !== void 0 ? _f : notImplemented('queueMicrotask'); | ||
this.setInterval = 'setInterval' in overrides ? overrides.setInterval : (_h = (_g = g.setInterval) === null || _g === void 0 ? void 0 : _g.bind(g)) !== null && _h !== void 0 ? _h : notImplemented('setInterval'); | ||
this.setTimeout = 'setTimeout' in overrides ? overrides.setTimeout : (_k = (_j = g.setTimeout) === null || _j === void 0 ? void 0 : _j.bind(g)) !== null && _k !== void 0 ? _k : notImplemented('setTimeout'); | ||
this.console = 'console' in overrides ? overrides.console : g.console; | ||
this.performanceNow = 'performanceNow' in overrides ? overrides.performanceNow : (_q = (_p = (_o = g.performance) === null || _o === void 0 ? void 0 : _o.now) === null || _p === void 0 ? void 0 : _p.bind(g.performance)) !== null && _q !== void 0 ? _q : notImplemented('performance.now'); | ||
this.performanceNow = 'performanceNow' in overrides ? overrides.performanceNow : (_o = (_m = (_l = g.performance) === null || _l === void 0 ? void 0 : _l.now) === null || _m === void 0 ? void 0 : _m.bind(g.performance)) !== null && _o !== void 0 ? _o : notImplemented('performance.now'); | ||
this.flushMacroTask = this.flushMacroTask.bind(this); | ||
@@ -46,2 +46,12 @@ this.macroTaskQueue = new TaskQueue(this, this.requestMacroTask.bind(this), this.cancelMacroTask.bind(this)); | ||
} | ||
static getOrCreate(g, overrides = {}) { | ||
let platform = lookup.get(g); | ||
if (platform === void 0) { | ||
lookup.set(g, platform = new Platform(g, overrides)); | ||
} | ||
return platform; | ||
} | ||
static set(g, platform) { | ||
lookup.set(g, platform); | ||
} | ||
requestMacroTask() { | ||
@@ -48,0 +58,0 @@ this.macroTaskRequested = true; |
{ | ||
"name": "@aurelia/platform", | ||
"version": "0.8.0-dev.202010270611", | ||
"version": "0.8.0-dev.202011010944", | ||
"main": "dist/umd/index.js", | ||
@@ -39,3 +39,3 @@ "module": "dist/esnext/index.js", | ||
}, | ||
"gitHead": "9eee6d164ee617fe089ffe380b7a498369511c59" | ||
"gitHead": "1047d63f267bb65bc78cfa1d48c4902164fb40d7" | ||
} |
@@ -1,15 +0,2 @@ | ||
// Limit the accessible properties to that of the native ES globalThis and WindowOrWorkerGlobalScope by default. | ||
// We need the whole DOM lib to have access to the WindowOrWorkerGlobalScope type, but that turns globalThis into a union with Window | ||
// which exposes properties we don't want to assume exist here. | ||
// Hence, we create a synthetic type that has only the properties we can more or less safely assume to exist. | ||
type GlobalThisOrWindowOrWorkerGlobalScope = Pick< | ||
typeof globalThis, | ||
Exclude< | ||
keyof typeof globalThis, | ||
Exclude< | ||
keyof Window, | ||
keyof WindowOrWorkerGlobalScope | ||
> | ||
> | ||
>; | ||
const lookup = new Map<object, Platform>(); | ||
@@ -22,3 +9,3 @@ function notImplemented(name: string): (...args: any[]) => any { | ||
export class Platform<TGlobal extends GlobalThisOrWindowOrWorkerGlobalScope = GlobalThisOrWindowOrWorkerGlobalScope> { | ||
export class Platform<TGlobal extends typeof globalThis = typeof globalThis> { | ||
// http://www.ecma-international.org/ecma-262/#sec-value-properties-of-the-global-object | ||
@@ -45,3 +32,2 @@ public readonly globalThis: TGlobal; | ||
public readonly clearTimeout: TGlobal['clearTimeout']; | ||
public readonly fetch: TGlobal['fetch']; | ||
public readonly queueMicrotask: TGlobal['queueMicrotask']; | ||
@@ -52,3 +38,3 @@ public readonly setInterval: TGlobal['setInterval']; | ||
public readonly performanceNow: TGlobal['performance']['now']; | ||
public readonly performanceNow: () => number; | ||
@@ -71,3 +57,2 @@ public readonly macroTaskQueue: TaskQueue; | ||
this.clearTimeout = 'clearTimeout' in overrides ? overrides.clearTimeout! : g.clearTimeout?.bind(g) ?? notImplemented('clearTimeout'); | ||
this.fetch = 'fetch' in overrides ? overrides.fetch! : g.fetch?.bind(g) ?? notImplemented('fetch'); | ||
this.queueMicrotask = 'queueMicrotask' in overrides ? overrides.queueMicrotask! : g.queueMicrotask?.bind(g) ?? notImplemented('queueMicrotask'); | ||
@@ -85,2 +70,17 @@ this.setInterval = 'setInterval' in overrides ? overrides.setInterval! : g.setInterval?.bind(g) ?? notImplemented('setInterval'); | ||
public static getOrCreate<TGlobal extends typeof globalThis = typeof globalThis>( | ||
g: TGlobal, | ||
overrides: Partial<Exclude<Platform, 'globalThis'>> = {}, | ||
): Platform<TGlobal> { | ||
let platform = lookup.get(g); | ||
if (platform === void 0) { | ||
lookup.set(g, platform = new Platform(g, overrides)); | ||
} | ||
return platform as Platform<TGlobal>; | ||
} | ||
public static set(g: typeof globalThis, platform: Platform): void { | ||
lookup.set(g, platform); | ||
} | ||
protected macroTaskRequested: boolean = false; | ||
@@ -87,0 +87,0 @@ protected macroTaskHandle: number = -1; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141278
2220