mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-13 06:42:23 +00:00
Stop sharing a Data Library entry as on once its failed Remove switched it off
When Remove switched a layer off and then its destroy failed, the manager published no visibility change, so the selection still listed the entry as on: the link shared it as on and a reload restored it on while its row read off. A failed Remove now drops the entry from what is on and remembered whenever its layer ended up off.
This commit is contained in:
1 parent
837eff7328
commit
8cca78bcd5
2 files changed
+47
-1
No files matched your search
@@ -388,8 +388,19 @@ export function createDataLibrary({
|
||||
if (
|
||||
isRegistered(id) &&
|
||||
!(await dataManager.unregisterLibraryLayer(libraryLayerId(id)))
|
||||
)
|
||||
) {
|
||||
// Switched off before teardown failed: it is no longer on, so the
|
||||
// link and what is remembered must not say it is.
|
||||
if (!dataManager.isEnabled?.(libraryLayerId(id))) {
|
||||
selection = {
|
||||
...selection,
|
||||
on: selection.on.filter((other) => other !== id),
|
||||
};
|
||||
savedOn = savedOn.filter((other) => other !== id);
|
||||
persist();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
selection = {
|
||||
added: selection.added.filter((other) => other !== id),
|
||||
on: selection.on.filter((other) => other !== id),
|
||||
|
||||
@@ -581,6 +581,41 @@ test('the URL keeps the opening lib= before availability loads and for entries i
|
||||
library.destroy();
|
||||
});
|
||||
|
||||
test('a layer switched off before its teardown failed is no longer shared as on', async (t) => {
|
||||
const manager = sealedManager(t);
|
||||
const storage = memoryStorage();
|
||||
const shareLink = shareLinkDouble();
|
||||
const library = createDataLibrary({
|
||||
entries,
|
||||
ledger,
|
||||
dataManager: manager,
|
||||
services: {},
|
||||
storage,
|
||||
shareLink,
|
||||
initialHash: '',
|
||||
source: source({}),
|
||||
});
|
||||
await library.start();
|
||||
await library.add('night-lights');
|
||||
assert.equal(shareLink.encode(), '00');
|
||||
const { module } = manager.layers.get('lib-night-lights');
|
||||
const destroy = module.destroy;
|
||||
module.destroy = async () => {
|
||||
throw new Error('stuck');
|
||||
};
|
||||
t.mock.method(console, 'warn', () => {});
|
||||
try {
|
||||
assert.equal(await library.remove('night-lights'), false);
|
||||
assert.equal(manager.isEnabled('lib-night-lights'), false);
|
||||
assert.equal(shareLink.encode(), null);
|
||||
const saved = JSON.parse(storage.store.get(LIBRARY_STORAGE_KEY));
|
||||
assert.deepEqual(saved, { added: ['night-lights'], on: [] });
|
||||
} finally {
|
||||
module.destroy = destroy;
|
||||
}
|
||||
library.destroy();
|
||||
});
|
||||
|
||||
test('zoom flies to an added layer through the caller, reset removes everything', async (t) => {
|
||||
const manager = sealedManager(t);
|
||||
const storage = memoryStorage();
|
||||
|
||||
Reference in new issue
Block a user