@@ -21,8 +21,21 @@ import { guid } from "../Utils.js";
2121import { KnownEventDataKeys } from "../models/Event.js" ;
2222
2323export class Configuration {
24+ private handler = {
25+ set : ( target , key , value ) => {
26+ console . log ( key , ` set to ${ value } ` ) ;
27+ target [ key ] = value ;
28+ return true ;
29+ }
30+ } ;
31+
32+ constructor ( ) {
33+ // TODO: Verify this works in derived classes.
34+ return new Proxy ( this , this . handler ) ;
35+ }
36+
2437 // TODO: add flag if your suspended.
25- // change version to be a string.
38+ // TODO: change version to be a string.
2639 /**
2740 * A default list of tags that will automatically be added to every
2841 * report submitted to the server.
@@ -57,12 +70,12 @@ export class Configuration {
5770 submissionClient ?: ISubmissionClient ,
5871 storage : IStorageProvider ,
5972 queue : IEventQueue
60- } = {
73+ } = new Proxy ( {
6174 lastReferenceIdManager : new DefaultLastReferenceIdManager ( ) ,
6275 log : new NullLog ( ) ,
6376 storage : new InMemoryStorageProvider ( ) ,
6477 queue : new DefaultEventQueue ( this )
65- } ;
78+ } , this . handler ) ;
6679
6780 /**
6881 * Maximum number of events that should be sent to the server together in a batch. (Defaults to 50)
@@ -140,11 +153,11 @@ export class Configuration {
140153 private _plugins : IEventPlugin [ ] = [ ] ;
141154
142155 /**
143- * A list of handlers that will be fired when configuration changes.
156+ * A list of subscribers that will be fired when configuration changes.
144157 * @type {Array }
145158 * @private
146159 */
147- private _handlers : Array < ( config : Configuration ) => void > = [ ] ;
160+ private _subscribers : Array < ( config : Configuration ) => void > = [ ] ;
148161
149162 /**
150163 * The API key that will be used when sending events to the server.
@@ -611,17 +624,17 @@ export class Configuration {
611624 this . services . log = new ConsoleLog ( ) ;
612625 }
613626
614- public onChanged ( handler : ( config : Configuration ) => void ) : void {
615- handler && this . _handlers . push ( handler ) ;
627+ public subscribe ( handler : ( config : Configuration ) => void ) : void {
628+ handler && this . _subscribers . push ( handler ) ;
616629 }
617630
618631 protected changed ( ) {
619- const handlers = this . _handlers ; // optimization for minifier.
632+ const handlers = this . _subscribers ; // optimization for minifier.
620633 for ( const handler of handlers ) {
621634 try {
622635 handler ( this ) ;
623636 } catch ( ex ) {
624- this . services . log . error ( `Error calling onChanged handler: ${ ex } ` ) ;
637+ this . services . log . error ( `Error calling subscribe handler: ${ ex } ` ) ;
625638 }
626639 }
627640 }
0 commit comments