@@ -32,23 +32,29 @@ export class MetadataManager {
3232 this . interval = window . setInterval ( ( ) => this . update ( ) , this . plugin . settings . syncInterval ) ;
3333 }
3434
35- register ( file : TFile , onCacheUpdate : ( metadata : Record < string , any > ) => void , uuid : string ) : void {
35+ register ( file : TFile , onCacheUpdate : ( metadata : Record < string , any > ) => void , uuid : string ) : MetadataFileCache {
3636 const fileCache = this . getCacheForFile ( file ) ;
3737 if ( fileCache ) {
38- console . debug ( `meta-bind | registered ${ uuid } to existing file cache` ) ;
38+ console . debug ( `meta-bind | MetadataManager >> registered ${ uuid } to existing file cache ${ file . path } ` ) ;
3939 fileCache . listeners . push ( { onCacheUpdate, uuid } ) ;
40+ return fileCache ;
4041 } else {
41- const c = {
42+ console . debug ( `meta-bind | MetadataManager >> registered ${ uuid } to newly created file cache ${ file . path } ` ) ;
43+ const c : MetadataFileCache = {
4244 file : file ,
4345 metadata : { } ,
4446 listeners : [ { onCacheUpdate, uuid } ] ,
4547 cyclesSinceLastUpdate : 0 ,
4648 changed : false ,
47- }
49+ } ;
4850
49- this . plugin . app . vault . cachedRead ( file ) . then ( value => c . metadata = getMetaDataFromFileContent ( value ) ) ;
51+ this . plugin . app . vault . cachedRead ( file ) . then ( value => {
52+ c . metadata = getMetaDataFromFileContent ( value ) ;
53+ this . notifyListeners ( c ) ;
54+ } ) ;
5055
5156 this . cache . push ( c ) ;
57+ return c ;
5258 }
5359 }
5460
@@ -58,8 +64,11 @@ export class MetadataManager {
5864 return ;
5965 }
6066
67+ console . debug ( `meta-bind | MetadataManager >> unregistered ${ uuid } to from file cache ${ file . path } ` ) ;
68+
6169 fileCache . listeners = fileCache . listeners . filter ( x => x . uuid !== uuid ) ;
6270 if ( fileCache . listeners . length === 0 ) {
71+ console . debug ( `meta-bind | MetadataManager >> deleted unused file cache ${ file . path } ` ) ;
6372 this . cache = this . cache . filter ( x => x . file . path !== file . path ) ;
6473 }
6574 }
@@ -80,11 +89,15 @@ export class MetadataManager {
8089 }
8190
8291 async updateFrontmatter ( fileCache : MetadataFileCache ) : Promise < void > {
92+ console . debug ( `meta-bind | MetadataManager >> updating frontmatter of ${ fileCache . file . path } to` , fileCache . metadata ) ;
93+
8394 fileCache . changed = false ;
8495 await setFrontmatterOfTFile ( fileCache . metadata , fileCache . file , this . plugin ) ;
8596 }
8697
8798 updateMetadataFileCache ( metadata : Record < string , any > , file : TFile , uuid ?: string | undefined ) : void {
99+ console . debug ( `meta-bind | MetadataManager >> updating metadata in ${ file . path } metadata cache to` , metadata ) ;
100+
88101 const fileCache = this . getCacheForFile ( file ) ;
89102 if ( ! fileCache ) {
90103 return ;
@@ -97,7 +110,7 @@ export class MetadataManager {
97110 }
98111
99112 updatePropertyInMetadataFileCache ( value : any , path : string , file : TFile , uuid ?: string | undefined ) : void {
100- console . debug ( `meta-bind | updating ${ path } in ${ file . path } metadata cache to` , value ) ;
113+ console . debug ( `meta-bind | MetadataManager >> updating ${ path } in ${ file . path } metadata cache to` , value ) ;
101114
102115 const fileCache = this . getCacheForFile ( file ) ;
103116 if ( ! fileCache ) {
@@ -130,7 +143,7 @@ export class MetadataManager {
130143 const metadata : Record < string , any > = Object . assign ( { } , cache . frontmatter ) ; // copy
131144 delete metadata . position ;
132145
133- console . debug ( `meta-bind | updating ${ file } on frontmatter update` , metadata ) ;
146+ console . debug ( `meta-bind | MetadataManager >> updating ${ file } on frontmatter update` , metadata ) ;
134147
135148 fileCache . metadata = metadata ;
136149 fileCache . cyclesSinceLastUpdate = 0 ;
@@ -144,6 +157,7 @@ export class MetadataManager {
144157 if ( exceptUuid && exceptUuid === listener . uuid ) {
145158 continue ;
146159 }
160+ console . debug ( `meta-bind | MetadataManager >> notifying input field ${ listener . uuid } of updated metadata` ) ;
147161 listener . onCacheUpdate ( fileCache . metadata ) ;
148162 }
149163 }
0 commit comments