@@ -5,6 +5,8 @@ export class RapidManager {
55 #baseUrl: string ;
66 #osmUrl: string ;
77 #tdeiAuth: TdeiAuthStore ;
8+ #stateCallback: ( ( state : any ) => void ) | null = null ;
9+
810
911 constructor ( baseUrl : string , osmUrl : string , tdeiAuth : TdeiAuthStore ) {
1012 this . #baseUrl = baseUrl ;
@@ -16,6 +18,16 @@ export class RapidManager {
1618 this . rapidContext = null ;
1719 }
1820
21+ onStateChange ( callback : ( state : any ) => void ) {
22+ this . #stateCallback = callback ;
23+ }
24+
25+ #notifyStateChange( state : any ) {
26+ if ( this . #stateCallback) {
27+ this . #stateCallback( state ) ;
28+ }
29+ }
30+
1931 load ( ) {
2032 if ( this . loaded . value ) {
2133 return
@@ -62,8 +74,10 @@ export class RapidManager {
6274 this . rapidContext . embed ( true ) ;
6375 this . rapidContext . containerNode = this . containerNode ;
6476 this . rapidContext . assetPath = this . #baseUrl;
77+
6578
66- console . info ( 'Rapid loaded' , this . rapidContext ) ;
79+ console . log ( 'Rapid loaded' , this . rapidContext ) ;
80+
6781 }
6882
6983 #patchRapid( ) {
@@ -75,6 +89,23 @@ export class RapidManager {
7589
7690 // Don't bother to fetch user details when uploading changesets:
7791 rapidOsmService . userDetails = ( callback ) => { callback ( 'dummy error' ) } ;
92+ // const editor = this.rapidContext.editor;
93+ // console.info('Rapid editor', editor);
94+ console . log ( 'Rapid editor ' , this . rapidContext ) ;
95+ const editSystem = this . rapidContext . systems . editor ;
96+ editSystem . on ( 'stablechange' , ( state ) => {
97+ // this.#notifyStateChange(state);
98+ const changes = editSystem . changes ( ) ;
99+ console . log ( 'Rapid editor changes' , changes ) ;
100+ const changesLength = changes . modified . length || changes . created . length || changes . deleted . length ;
101+
102+ this . #notifyStateChange( changesLength ) ;
103+
104+ } ) ;
105+
106+ // editSystem.on('reset', () => {
107+ // console.log('Rapid editor reset');
108+ // });
78109 }
79110
80111 #wrapFetch( innerFetch ) {
0 commit comments