« get me outta code hell

yaml, test: mutate/decache wikiData in more reusable ways - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/lib
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-08-25 14:06:00 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-05 21:02:52 -0300
commitf562896d4d67558a32726f7086beebf29019a44d (patch)
treeb4f9b9c16eba37abdcef26b18723d9acc7e406df /test/lib
parent087564095ff06fed25a0c21fab01ed9d849937d0 (diff)
yaml, test: mutate/decache wikiData in more reusable ways
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/index.js1
-rw-r--r--test/lib/wiki-data.js24
2 files changed, 25 insertions, 0 deletions
diff --git a/test/lib/index.js b/test/lib/index.js
index b9cc82f..6eaaa65 100644
--- a/test/lib/index.js
+++ b/test/lib/index.js
@@ -1,3 +1,4 @@
 export * from './content-function.js';
 export * from './generic-mock.js';
+export * from './wiki-data.js';
 export * from './strict-match-error.js';
diff --git a/test/lib/wiki-data.js b/test/lib/wiki-data.js
new file mode 100644
index 0000000..c4083a5
--- /dev/null
+++ b/test/lib/wiki-data.js
@@ -0,0 +1,24 @@
+import {linkWikiDataArrays} from '#yaml';
+
+export function linkAndBindWikiData(wikiData) {
+  linkWikiDataArrays(wikiData);
+
+  return {
+    // Mutate to make the below functions aware of new data objects, or of
+    // reordering the existing ones. Don't mutate arrays such as trackData
+    // in-place; assign completely new arrays to this wikiData object instead.
+    wikiData,
+
+    // Use this after you've mutated wikiData to assign new data arrays.
+    // It'll automatically relink everything on wikiData so all the objects
+    // are caught up to date.
+    linkWikiDataArrays:
+      linkWikiDataArrays.bind(null, wikiData),
+
+    // Use this if you HAVEN'T mutated wikiData and just need to decache
+    // indirect dependencies on exposed properties of other data objects.
+    // See documentation on linkWikiDataArarys (in yaml.js) for more info.
+    XXX_decacheWikiData:
+      linkWikiDataArrays.bind(null, wikiData, {XXX_decacheWikiData: true}),
+  };
+}