Skip to content

Commit 4b55688

Browse files
committed
apply default options in constructor only, ensure setOptions preserves missing values
1 parent f541ea8 commit 4b55688

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ export class I18n {
123123
private activeMessages: object = reactive({})
124124

125125
/**
126-
* Creates a new instance of the I18n class
126+
* Creates a new instance of the I18n class, applying default options
127127
*/
128128
constructor(options: OptionsInterface = {}) {
129-
this.setOptions(options)
129+
this.options = { ...DEFAULT_OPTIONS, ...options }
130130

131131
this[isServer ? 'loadLanguage' : 'loadLanguageAsync'](this.getActiveLanguage())
132132
}
133133

134134
/**
135-
* Sets options on the instance
135+
* Sets options on the instance, preserving any values not present in new options
136136
*/
137137
setOptions(options: OptionsInterface = {}): I18n {
138-
this.options = { ...DEFAULT_OPTIONS, ...options }
138+
this.options = { ...this.options, ...options }
139139

140140
return this
141141
}

0 commit comments

Comments
 (0)