@@ -9,6 +9,7 @@ import MetaBindTableComponent from './MetaBindTableComponent.svelte';
99import { ViewFieldMDRC } from '../renderChildren/ViewFieldMDRC' ;
1010import { Component } from 'obsidian' ;
1111import { UnvalidatedViewFieldDeclaration , ViewFieldDeclaration } from '../parsers/viewFieldParser/ViewFieldDeclaration' ;
12+ import { MetadataSubscription } from '../metadata/MetadataFileCache' ;
1213
1314export type MetaBindTableCell = InputFieldDeclaration | ViewFieldDeclaration ;
1415
@@ -29,16 +30,18 @@ export class MetaBindTable extends AbstractMDRC {
2930 columns : MetaBindColumnDeclaration [ ] ;
3031 tableComponent : MetaBindTableComponent | undefined ;
3132
32- private metadataManagerReadSignalListener : Listener < T | undefined > | undefined ;
33+ private metadataManagerOutputSignalListener : Listener < T | undefined > | undefined ;
3334
3435 /**
3536 * Signal to write to the input field
3637 */
37- public writeSignal : Signal < T | undefined > ;
38+ public inputSignal : Signal < T | undefined > ;
3839 /**
3940 * Signal to read from the input field
4041 */
41- public readSignal : Signal < T | undefined > ;
42+ public outputSignal : Signal < T | undefined > ;
43+
44+ private metadataSubscription ?: MetadataSubscription ;
4245
4346 constructor (
4447 containerEl : HTMLElement ,
@@ -55,30 +58,34 @@ export class MetaBindTable extends AbstractMDRC {
5558 this . tableHead = tableHead ;
5659 this . columns = columns ;
5760
58- this . writeSignal = new Signal < T | undefined > ( undefined ) ;
59- this . readSignal = new Signal < T | undefined > ( undefined ) ;
61+ this . inputSignal = new Signal < T | undefined > ( undefined ) ;
62+ this . outputSignal = new Signal < T | undefined > ( undefined ) ;
6063 }
6164
6265 registerSelfToMetadataManager ( ) : undefined {
63- this . metadataManagerReadSignalListener = this . readSignal . registerListener ( { callback : this . updateMetadataManager . bind ( this ) } ) ;
66+ this . metadataManagerOutputSignalListener = this . outputSignal . registerListener ( { callback : this . updateMetadataManager . bind ( this ) } ) ;
6467
65- this . plugin . metadataManager . register ( this . bindTarget . filePath ?? this . filePath , this . writeSignal , this . bindTarget . metadataPath , false , this . uuid ) ;
68+ this . metadataSubscription = this . plugin . metadataManager . subscribe (
69+ this . uuid ,
70+ this . inputSignal ,
71+ this . plugin . api . bindTargetParser . toFullDeclaration ( this . bindTarget , this . filePath )
72+ ) ;
6673 }
6774
6875 unregisterSelfFromMetadataManager ( ) : void {
69- if ( this . metadataManagerReadSignalListener ) {
70- this . readSignal . unregisterListener ( this . metadataManagerReadSignalListener ) ;
76+ if ( this . metadataManagerOutputSignalListener ) {
77+ this . outputSignal . unregisterListener ( this . metadataManagerOutputSignalListener ) ;
7178 }
7279
73- this . plugin . metadataManager . unregister ( this . bindTarget . filePath ?? this . filePath , this . uuid ) ;
80+ this . metadataSubscription ?. unsubscribe ( ) ;
7481 }
7582
7683 updateMetadataManager ( value : unknown ) : void {
77- this . plugin . metadataManager . updatePropertyInCache ( value , this . bindTarget . metadataPath , this . bindTarget . filePath ?? this . filePath , this . uuid ) ;
84+ this . metadataSubscription ?. update ( value ) ;
7885 }
7986
8087 getInitialValue ( ) : T {
81- return this . writeSignal . get ( ) ?? [ ] ;
88+ return this . inputSignal . get ( ) ?? [ ] ;
8289 }
8390
8491 updateDisplayValue ( values : T | undefined ) : void {
@@ -90,6 +97,7 @@ export class MetaBindTable extends AbstractMDRC {
9097 const scope = new BindTargetScope ( {
9198 metadataPath : [ ...this . bindTarget . metadataPath , i . toString ( ) ] ,
9299 filePath : this . bindTarget . filePath ,
100+ listenToChildren : false ,
93101 boundToLocalScope : false ,
94102 } ) ;
95103
@@ -132,16 +140,16 @@ export class MetaBindTable extends AbstractMDRC {
132140 }
133141
134142 removeColumn ( index : number ) : void {
135- const value = this . writeSignal . get ( ) ?? [ ] ;
143+ const value = this . inputSignal . get ( ) ?? [ ] ;
136144 value . splice ( index , 1 ) ;
137- this . readSignal . set ( value ) ;
145+ this . outputSignal . set ( value ) ;
138146 this . updateDisplayValue ( value ) ;
139147 }
140148
141149 addColumn ( ) : void {
142- const value = this . writeSignal . get ( ) ?? [ ] ;
150+ const value = this . inputSignal . get ( ) ?? [ ] ;
143151 value . push ( { } ) ;
144- this . readSignal . set ( value ) ;
152+ this . outputSignal . set ( value ) ;
145153 this . updateDisplayValue ( value ) ;
146154 }
147155
@@ -156,13 +164,13 @@ export class MetaBindTable extends AbstractMDRC {
156164 } ,
157165 } ) ;
158166
159- this . writeSignal . registerListener ( {
167+ this . inputSignal . registerListener ( {
160168 callback : values => {
161169 this . updateDisplayValue ( values ) ;
162170 } ,
163171 } ) ;
164172
165- this . updateDisplayValue ( this . writeSignal . get ( ) ) ;
173+ this . updateDisplayValue ( this . inputSignal . get ( ) ) ;
166174 }
167175
168176 public onunload ( ) : void {
0 commit comments