1- import { areArraysEqual , arrayStartsWith , traverseObjectToParentByPath } from '../utils/Utils' ;
2- import { traverseObjectByPath } from '@opd-libs/opd-utils-lib/lib/ObjectTraversalUtils' ;
1+ import { areArraysEqual , arrayStartsWith } from '../utils/Utils' ;
32import { type Signal } from '../utils/Signal' ;
43import { type Metadata , type MetadataManagerCacheItem } from './MetadataManagerCacheItem' ;
54import { type FullBindTarget } from '../parsers/inputFieldParser/InputFieldDeclaration' ;
@@ -12,6 +11,8 @@ import {
1211 type ComputedSubscriptionDependency ,
1312 type ComputeFunction ,
1413} from './ComputedMetadataSubscription' ;
14+ import { PropUtils } from '../utils/prop/PropUtils' ;
15+ import { type PropPath } from '../utils/prop/PropPath' ;
1516
1617export const metadataCacheUpdateCycleThreshold = 5 ; // {syncInterval (200)} * 5 = 1s
1718export const metadataCacheInactiveCycleThreshold = 5 * 60 ; // {syncInterval (200)} * 5 * 60 = 1 minute
@@ -31,7 +32,11 @@ function hasUpdateOverlap(a: FullBindTarget | undefined, b: FullBindTarget | und
3132 return false ;
3233 }
3334
34- return metadataPathHasUpdateOverlap ( a . metadataPath , b . metadataPath , b . listenToChildren ) ;
35+ return metadataPathHasUpdateOverlap (
36+ a . metadataPath . toStringArray ( ) ,
37+ b . metadataPath . toStringArray ( ) ,
38+ b . listenToChildren ,
39+ ) ;
3540}
3641
3742/**
@@ -62,7 +67,7 @@ function bindTargetToString(a: FullBindTarget | undefined): string {
6267 return 'undefined' ;
6368 }
6469
65- return `${ a . filePath } #${ a . metadataPath } ` ;
70+ return `${ a . filePath } #${ a . metadataPath . toString ( ) } ` ;
6671}
6772
6873export class MetadataManager {
@@ -97,17 +102,21 @@ export class MetadataManager {
97102
98103 if ( fileCache ) {
99104 console . debug (
100- `meta-bind | MetadataManager >> registered ${ subscription . uuid } to existing file cache ${ subscription . bindTarget . filePath } -> ${ subscription . bindTarget . metadataPath } ` ,
105+ `meta-bind | MetadataManager >> registered ${ subscription . uuid } to existing file cache ${
106+ subscription . bindTarget . filePath
107+ } -> ${ subscription . bindTarget . metadataPath . toString ( ) } `,
101108 ) ;
102109
103110 fileCache . inactive = false ;
104111 fileCache . cyclesSinceInactive = 0 ;
105112 fileCache . listeners . push ( subscription ) ;
106113
107- subscription . notify ( traverseObjectByPath ( subscription . bindTarget . metadataPath , fileCache . metadata ) ) ;
114+ subscription . notify ( PropUtils . tryGet ( fileCache . metadata , subscription . bindTarget . metadataPath ) ) ;
108115 } else {
109116 console . debug (
110- `meta-bind | MetadataManager >> registered ${ subscription . uuid } to newly created file cache ${ subscription . bindTarget . filePath } -> ${ subscription . bindTarget . metadataPath } ` ,
117+ `meta-bind | MetadataManager >> registered ${ subscription . uuid } to newly created file cache ${
118+ subscription . bindTarget . filePath
119+ } -> ${ subscription . bindTarget . metadataPath . toString ( ) } `,
111120 ) ;
112121
113122 // const file = this.plugin.app.vault.getAbstractFileByPath(subscription.bindTarget.filePath) as TFile;
@@ -129,7 +138,7 @@ export class MetadataManager {
129138 newCache . metadata ,
130139 ) ;
131140
132- subscription . notify ( traverseObjectByPath ( subscription . bindTarget . metadataPath , newCache . metadata ) ) ;
141+ subscription . notify ( PropUtils . tryGet ( newCache . metadata , subscription . bindTarget . metadataPath ) ) ;
133142
134143 this . createCacheForFile ( subscription . bindTarget . filePath , newCache ) ;
135144 }
@@ -400,18 +409,8 @@ export class MetadataManager {
400409 return ;
401410 }
402411
403- const { parent , child } = traverseObjectToParentByPath ( metadataPath , fileCache . metadata ) ;
412+ PropUtils . setAndCreate ( fileCache . metadata , metadataPath , value ) ;
404413
405- if ( parent . value == null ) {
406- throw Error (
407- `The parent of "${ JSON . stringify (
408- metadataPath ,
409- ) } " does not exist in Object, please create the parent first`,
410- ) ;
411- }
412-
413- // @ts -ignore
414- parent . value [ child . key ] = value ;
415414 fileCache . cyclesSinceLastChange = 0 ;
416415 fileCache . changed = true ;
417416
@@ -454,7 +453,7 @@ export class MetadataManager {
454453 */
455454 notifyListeners (
456455 fileCache : MetadataManagerCacheItem ,
457- metadataPath ?: string [ ] | undefined ,
456+ metadataPath ?: PropPath | undefined ,
458457 exceptUuid ?: string | undefined ,
459458 ) : void {
460459 // console.log(fileCache);
@@ -471,20 +470,20 @@ export class MetadataManager {
471470 if ( metadataPath ) {
472471 if (
473472 metadataPathHasUpdateOverlap (
474- metadataPath ,
475- listener . bindTarget . metadataPath ,
473+ metadataPath . toStringArray ( ) ,
474+ listener . bindTarget . metadataPath . toStringArray ( ) ,
476475 listener . bindTarget . listenToChildren ,
477476 )
478477 ) {
479- const value : unknown = traverseObjectByPath ( listener . bindTarget . metadataPath , fileCache . metadata ) ;
478+ const value : unknown = PropUtils . tryGet ( fileCache . metadata , listener . bindTarget . metadataPath ) ;
480479 console . debug (
481480 `meta-bind | MetadataManager >> notifying input field ${ listener . uuid } of updated metadata value` ,
482481 value ,
483482 ) ;
484483 listener . notify ( value ) ;
485484 }
486485 } else {
487- const value : unknown = traverseObjectByPath ( listener . bindTarget . metadataPath , fileCache . metadata ) ;
486+ const value : unknown = PropUtils . tryGet ( fileCache . metadata , listener . bindTarget . metadataPath ) ;
488487 console . debug (
489488 `meta-bind | MetadataManager >> notifying input field ${ listener . uuid } of updated metadata` ,
490489 listener . bindTarget . metadataPath ,
0 commit comments