mirror of
https://github.com/motajs/template.git
synced 2026-09-15 03:18:50 +08:00
test(event): polyfill map insertion in fixtures
This commit is contained in:
parent
63d4d37ff3
commit
33966fb4dd
@ -16,6 +16,17 @@ let modules: TestModules;
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
Map.prototype.getOrInsertComputed ??= function <K, V>(
|
||||
this: Map<K, V>,
|
||||
key: K,
|
||||
callback: (key: K) => V
|
||||
): V {
|
||||
const existing = this.get(key);
|
||||
if (existing !== undefined) return existing;
|
||||
const value = callback(key);
|
||||
this.set(key, value);
|
||||
return value;
|
||||
};
|
||||
const mapModule = await import('./mapState');
|
||||
const commonModule = await import('@user/data-common');
|
||||
const loggerModule = await import('@motajs/common');
|
||||
|
||||
@ -213,20 +213,10 @@ export class MapLayer
|
||||
event(x: number, y: number): ILayerEventView | null {
|
||||
if (!this.inMap(x, y)) return null;
|
||||
const index = y * this.width + x;
|
||||
const getOrInsertComputed = this.pointEvents.getOrInsertComputed;
|
||||
if (getOrInsertComputed) {
|
||||
return getOrInsertComputed.call(
|
||||
this.pointEvents,
|
||||
index,
|
||||
() => new LayerEventView()
|
||||
);
|
||||
}
|
||||
let eventView = this.pointEvents.get(index);
|
||||
if (!eventView) {
|
||||
eventView = new LayerEventView();
|
||||
this.pointEvents.set(index, eventView);
|
||||
}
|
||||
return eventView;
|
||||
return this.pointEvents.getOrInsertComputed(
|
||||
index,
|
||||
() => new LayerEventView()
|
||||
);
|
||||
}
|
||||
|
||||
getPointEvent(x: number, y: number): ReadonlyMap<number, string> | null {
|
||||
|
||||
@ -9,6 +9,17 @@ import {
|
||||
vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
Map.prototype.getOrInsertComputed ??= function <K, V>(
|
||||
this: Map<K, V>,
|
||||
key: K,
|
||||
callback: (key: K) => V
|
||||
): V {
|
||||
const existing = this.get(key);
|
||||
if (existing !== undefined) return existing;
|
||||
const value = callback(key);
|
||||
this.set(key, value);
|
||||
return value;
|
||||
};
|
||||
});
|
||||
|
||||
interface TestModules {
|
||||
|
||||
@ -18,6 +18,17 @@ import { AnonTokyoInterpreter } from 'anon-tokyo';
|
||||
vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
Map.prototype.getOrInsertComputed ??= function <K, V>(
|
||||
this: Map<K, V>,
|
||||
key: K,
|
||||
callback: (key: K) => V
|
||||
): V {
|
||||
const existing = this.get(key);
|
||||
if (existing !== undefined) return existing;
|
||||
const value = callback(key);
|
||||
this.set(key, value);
|
||||
return value;
|
||||
};
|
||||
});
|
||||
|
||||
const eventTriggers = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user