Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execute } from "./CacheStoreRemoveTimerService";
import { execute as cacheStoreGetService } from "./CacheStoreGetService";
import { describe, expect, it } from "vitest";
import { $cacheStore } from "../..";

Expand All @@ -19,4 +20,29 @@ describe("CacheStoreRemoveTimerService.js test", () =>
expect(data.has("trash")).toBe(true);
expect(trash.size).toBe(1);
});

it("a cache shared with an object that is still drawn is not discarded", () =>
{
const trash = new Map();
const data = new Map();
const store = new Map();
store.set("3", data);

// 表示オブジェクトが付ける自分の ID の印と、描画キャッシュ
data.set("3", true);
data.set("100", "node");

// 共有している片方がステージから外れる
execute($cacheStore, store, trash, "3");
expect(trash.has("3")).toBe(true);

// 印が外れるので、まだ描かれているもう片方は内側の Map を直接使い続けない
expect(data.has("3")).toBe(false);
expect(data.get("100")).toBe("node");

// 次の描画で CacheStore.get を通ると、削除の予約が取り消される
expect(cacheStoreGetService($cacheStore, store, trash, "3", "100")).toBe("node");
expect(trash.has("3")).toBe(false);
expect(data.has("trash")).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ export const execute = (
data.set("trash", true);
trash_store.set(id, data);

// 同じ内容の表示オブジェクトは、このキャッシュを共有する。共有している別のオブジェクトがまだ
// ステージにあるときに捨ててしまうと、そのオブジェクトは次の描画で全部作り直しになる。
// 表示オブジェクトは内側の Map を直接持ち、自分の ID の印があるかだけを見て使い続けるので、
// ここで印を外す。まだ描かれているオブジェクトは、次の描画で印が無いことに気づいて
// CacheStore.get を通り、そこで削除の予約が取り消される。描かれなければ、従来どおり捨てられる。
// Display objects with the same content share this cache. Discarding it while another object
// that shares it is still on the stage makes that object rebuild everything on its next draw.
// A display object keeps the inner Map directly and only checks its own ID marker, so the marker
// is removed here: an object that is still being drawn notices it on the next draw, goes through
// CacheStore.get and the scheduled removal is cancelled there. Otherwise it is discarded as before.
data.delete(id);

if (cache_store.$timerId !== null) {
clearTimeout(cache_store.$timerId);
}
Expand Down
Loading