mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
fix(maps): stop delivering settled state to detached subscribers
This commit is contained in:
1 parent
0265ad4c19
commit
5889d35327
4 files changed
+62
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { MapSourceController } from './controller.js';
|
||||
function fixture() {
|
||||
return new MapSourceController(
|
||||
{
|
||||
scene: {
|
||||
globe: { show: true },
|
||||
requestRender() {},
|
||||
frameState: {
|
||||
creditDisplay: { addStaticCredit() {}, removeStaticCredit() {} },
|
||||
},
|
||||
primitives: { add() {}, remove() {} },
|
||||
},
|
||||
imageryLayers: { add() {}, remove() {} },
|
||||
},
|
||||
{
|
||||
registry: {
|
||||
defaultId: 'fixture',
|
||||
sources: [
|
||||
{
|
||||
descriptor: { id: 'fixture', label: 'Fixture', kind: 'imagery' },
|
||||
imagery: async () => ({}),
|
||||
},
|
||||
],
|
||||
},
|
||||
createImageryLayer: (provider) => ({ provider }),
|
||||
},
|
||||
);
|
||||
}
|
||||
test('an unsubscribed owner is skipped in the same map settlement delivery', async () => {
|
||||
const controller = fixture();
|
||||
const calls = [];
|
||||
let detach;
|
||||
controller.subscribe(() => {
|
||||
calls.push('first');
|
||||
detach();
|
||||
});
|
||||
detach = controller.subscribe(() => calls.push('detached'));
|
||||
controller.subscribe(() => calls.push('last'));
|
||||
await controller.setStack('fixture');
|
||||
assert.deepEqual(calls, ['first', 'last']);
|
||||
controller.destroy();
|
||||
});
|
||||
test('destroying the controller during delivery stops remaining listeners', async () => {
|
||||
const controller = fixture();
|
||||
const calls = [];
|
||||
controller.subscribe(() => {
|
||||
calls.push('destroy');
|
||||
controller.destroy();
|
||||
});
|
||||
controller.subscribe(() => calls.push('detached'));
|
||||
await controller.setStack('fixture');
|
||||
assert.deepEqual(calls, ['destroy']);
|
||||
});
|
||||
Reference in new issue
Block a user