@@ -28,25 +28,24 @@ const ENTRY_TYPES = [
2828 "pairedDelimiter" ,
2929] as const ;
3030
31+ type Writable < T > = {
32+ - readonly [ K in keyof T ] : T [ K ] ;
33+ } ;
34+
3135/**
3236 * Maintains a list of all scope types and notifies listeners when it changes.
3337 */
34- export class CustomSpokenForms implements SpokenFormMap {
38+ export class CustomSpokenForms {
3539 private disposer = new Disposer ( ) ;
3640 private notifier = new Notifier ( ) ;
3741
38- // Initialize to defaults
39- simpleScopeTypeType = defaultSpokenFormMap . simpleScopeTypeType ;
40- pairedDelimiter = defaultSpokenFormMap . pairedDelimiter ;
41- customRegex = defaultSpokenFormMap . customRegex ;
42+ private spokenFormMap_ : Writable < SpokenFormMap > = { ...defaultSpokenFormMap } ;
4243
43- // FIXME: Get these from Talon
44- surroundingPairForceDirection =
45- defaultSpokenFormMap . surroundingPairForceDirection ;
46- simpleModifier = defaultSpokenFormMap . simpleModifier ;
47- modifierExtra = defaultSpokenFormMap . modifierExtra ;
44+ get spokenFormMap ( ) : SpokenFormMap {
45+ return this . spokenFormMap_ ;
46+ }
4847
49- private isInitialized_ = false ;
48+ private customSpokenFormsInitialized_ = false ;
5049 private needsInitialTalonUpdate_ : boolean | undefined ;
5150
5251 /**
@@ -62,8 +61,8 @@ export class CustomSpokenForms implements SpokenFormMap {
6261 * default spoken forms are currently being used while the custom spoken forms
6362 * are being loaded.
6463 */
65- get isInitialized ( ) {
66- return this . isInitialized_ ;
64+ get customSpokenFormsInitialized ( ) {
65+ return this . customSpokenFormsInitialized_ ;
6766 }
6867
6968 constructor ( private talonSpokenForms : TalonSpokenForms ) {
@@ -88,9 +87,7 @@ export class CustomSpokenForms implements SpokenFormMap {
8887 } catch ( err ) {
8988 if ( err instanceof NeedsInitialTalonUpdateError ) {
9089 // Handle case where spokenForms.json doesn't exist yet
91- console . log ( err . message ) ;
9290 this . needsInitialTalonUpdate_ = true ;
93- this . notifier . notifyListeners ( ) ;
9491 } else {
9592 console . error ( "Error loading custom spoken forms" , err ) ;
9693 showError (
@@ -102,6 +99,10 @@ export class CustomSpokenForms implements SpokenFormMap {
10299 ) ;
103100 }
104101
102+ this . spokenFormMap_ = { ...defaultSpokenFormMap } ;
103+ this . customSpokenFormsInitialized_ = false ;
104+ this . notifier . notifyListeners ( ) ;
105+
105106 return ;
106107 }
107108
@@ -118,7 +119,7 @@ export class CustomSpokenForms implements SpokenFormMap {
118119 const ids = Array . from (
119120 new Set ( [ ...Object . keys ( defaultEntry ) , ...Object . keys ( entry ) ] ) ,
120121 ) ;
121- this [ entryType ] = Object . fromEntries (
122+ this . spokenFormMap_ [ entryType ] = Object . fromEntries (
122123 ids . map ( ( id ) : [ SpokenFormType , SpokenFormMapEntry ] => {
123124 const { defaultSpokenForms = [ ] , isSecret = false } =
124125 defaultEntry [ id ] ?? { } ;
@@ -151,12 +152,12 @@ export class CustomSpokenForms implements SpokenFormMap {
151152 ) as any ;
152153 }
153154
154- this . isInitialized_ = true ;
155+ this . customSpokenFormsInitialized_ = true ;
155156 this . notifier . notifyListeners ( ) ;
156157 }
157158
158159 getCustomRegexScopeTypes ( ) : CustomRegexScopeType [ ] {
159- return Object . keys ( this . customRegex ) . map ( ( regex ) => ( {
160+ return Object . keys ( this . spokenFormMap_ . customRegex ) . map ( ( regex ) => ( {
160161 type : "customRegex" ,
161162 regex,
162163 } ) ) ;
0 commit comments