« get me outta code hell

data, test: withPropertyFromObject: 'internal' input - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-04 13:32:37 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:00 -0300
commit94469a4c77e02a51c3d15cc86a7fc4b3fbf63785 (patch)
tree366a5946231588831713772d24178b1cebf4cf39 /src
parenta83e97eb931487520da96b5efcb6cdf14c950d63 (diff)
data, test: withPropertyFromObject: 'internal' input
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/data/withPropertyFromObject.js28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/data/composite/data/withPropertyFromObject.js b/src/data/composite/data/withPropertyFromObject.js
index b31bab15..4f240506 100644
--- a/src/data/composite/data/withPropertyFromObject.js
+++ b/src/data/composite/data/withPropertyFromObject.js
@@ -2,11 +2,15 @@
 // If the object itself is null, or the object doesn't have the listed property,
 // the provided dependency will also be null.
 //
+// If the `internal` input is true, this reads the CacheableObject update value
+// of the object rather than its exposed value.
+//
 // See also:
 //  - withPropertiesFromObject
 //  - withPropertyFromList
 //
 
+import CacheableObject from '#cacheable-object';
 import {input, templateCompositeFrom} from '#composite';
 
 export default templateCompositeFrom({
@@ -15,6 +19,7 @@ export default templateCompositeFrom({
   inputs: {
     object: input({type: 'object', acceptsNull: true}),
     property: input({type: 'string'}),
+    internal: input({type: 'boolean', defaultValue: false}),
   },
 
   outputs: ({
@@ -49,20 +54,35 @@ export default templateCompositeFrom({
 
     {
       dependencies: [
-        '#output',
         input('object'),
         input('property'),
+        input('internal'),
       ],
 
       compute: (continuation, {
-        ['#output']: output,
         [input('object')]: object,
         [input('property')]: property,
+        [input('internal')]: internal,
       }) => continuation({
-        [output]:
+        '#value':
           (object === null
             ? null
-            : object[property] ?? null),
+         : internal
+            ? CacheableObject.getUpdateValue(object, property)
+                ?? null
+            : object[property]
+                ?? null),
+      }),
+    },
+
+    {
+      dependencies: ['#output', '#value'],
+
+      compute: (continuation, {
+        ['#output']: output,
+        ['#value']: value,
+      }) => continuation({
+        [output]: value,
       }),
     },
   ],