« get me outta code hell

find: pass thingConstructors into include() - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-04-06 17:39:06 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-04-10 16:02:41 -0300
commit9696dbe1688dcf9641875ea7a4fab50c5776017b (patch)
tree486dd3a561ce65cc7022284ea7c0e3452a5c4e26
parent498aa6648fe134810d60a090517189241d63f652 (diff)
find: pass thingConstructors into include()
Allow include() to conveniently replicate the same behavior
that it does by default, e.g. if [Thing.findThisThingOnly]
has been expressly disabled.
-rw-r--r--src/data/checks.js2
-rw-r--r--src/find.js8
2 files changed, 5 insertions, 5 deletions
diff --git a/src/data/checks.js b/src/data/checks.js
index a70f7d06..44f640a6 100644
--- a/src/data/checks.js
+++ b/src/data/checks.js
@@ -50,7 +50,7 @@ export function reportDirectoryErrors(wikiData, {
     if (!thingData) continue;
 
     for (const thing of thingData) {
-      if (findSpec.include && !findSpec.include(thing)) {
+      if (findSpec.include && !findSpec.include(thing, thingConstructors)) {
         continue;
       }
 
diff --git a/src/find.js b/src/find.js
index e590bc4f..e7f5cda1 100644
--- a/src/find.js
+++ b/src/find.js
@@ -42,7 +42,7 @@ export function processAvailableMatchesByName(data, {
   multipleNameMatches = Object.create(null),
 }) {
   for (const thing of data) {
-    if (!include(thing)) continue;
+    if (!include(thing, thingConstructors)) continue;
 
     for (const name of getMatchableNames(thing)) {
       if (typeof name !== 'string') {
@@ -79,7 +79,7 @@ export function processAvailableMatchesByDirectory(data, {
   results = Object.create(null),
 }) {
   for (const thing of data) {
-    if (!include(thing)) continue;
+    if (!include(thing, thingConstructors)) continue;
 
     for (const directory of getMatchableDirectories(thing)) {
       if (typeof directory !== 'string') {
@@ -266,9 +266,9 @@ export function postprocessFindSpec(spec, {thingConstructor}) {
   if (spec[Symbol.for('Thing.findThisThingOnly')] !== false) {
     if (spec.include) {
       const oldInclude = spec.include;
-      newSpec.include = thing =>
+      newSpec.include = (thing, ...args) =>
         thing instanceof thingConstructor &&
-        oldInclude(thing);
+        oldInclude(thing, ...args);
     } else {
       newSpec.include = thing =>
         thing instanceof thingConstructor;