@@ -26,16 +26,16 @@ Simple state management for TypeScript.
2626 * [ ` ArrayState ` ] ( #arraystate )
2727 * [ ` BooleanArrayState ` ] ( #booleanarraystate )
2828 * [ ` NamedArrayState ` ] ( #namedarraystate )
29- * [ ` NamedBooleanArrayState ` ] ( #namedbooleanarraystate )
30- * [ ` Boolean ` ] ( #boolean )
29+ * ` NamedBooleanArrayState `
30+ * ` Boolean `
3131 * [ ` BooleanState ` ] ( #booleanstate )
32- * [ ` Enum ` ] ( #enum )
32+ * ` Enum `
3333 * [ ` EnumState ` ] ( #enumstate )
3434 * [ ` BooleanActionObjectState ` ] ( #booleanactionobjectstate )
35- * [ ` BooleanObjectState ` ] ( #booleanobjectstate )
36- * [ ` NamedObjectState ` ] ( #namedobjectstate )
37- * [ ` ObjectState ` ] ( #objectstate )
38- * [ ` ImmutableState ` ] ( #immutablestate )
35+ * ` BooleanObjectState `
36+ * ` NamedObjectState `
37+ * ` ObjectState `
38+ * ` ImmutableState `
3939 * [ ` NullState ` ] ( #nullstate )
4040 * [ ` NumberState ` ] ( #numberstate )
4141 * [ ` State ` ] ( #state )
@@ -247,18 +247,49 @@ console.log(booleanArrayState.state); // Output: [true, true, true, true]
247247
248248``` typescript
249249import { NamedArrayState } from ' @typescript-package/state' ;
250- ```
251250
252- ### ` NamedBooleanArrayState `
251+ // Extend the NamedArrayState class for a specific type
252+ export class AppConfiguration extends NamedArrayState <' theme' | ' language' | ' notifications' , string | boolean > {
253+ constructor () {
254+ super (
255+ [' theme' , ' language' , ' notifications' ], // Names of the configuration settings
256+ [' dark' , ' en' , true ] // Default values
257+ );
258+ }
253259
254- ``` typescript
255- import { NamedBooleanArrayState } from ' @typescript-package/state' ;
256- ```
260+ /**
261+ * Updates the value of a specific configuration by name.
262+ * @param {string} name - The name of the configuration to update.
263+ * @param {string | boolean} value - The new value to set.
264+ */
265+ public updateConfiguration(name : ' theme' | ' language' | ' notifications' , value : string | boolean ) {
266+ this .update (this .indexOf (name ), value );
267+ }
268+ }
269+
270+ // Initialize.
271+ const config = new AppConfiguration ();
257272
258- ### ` Boolean `
273+ // View the current state as an object
274+ console .log (config .toObject ()); // Output: { theme: 'dark', language: 'en', notifications: true }
259275
260- ``` typescript
261- import { Boolean } from ' @typescript-package/state' ;
276+ // Get the value of a specific setting
277+ console .log (config .get (' theme' )); // Output: 'dark'
278+
279+ // Update a specific configuration setting
280+ config .updateConfiguration (' theme' , ' light' );
281+ console .log (config .get (' theme' )); // Output: 'light'
282+
283+ // Selecting multiple configuration options
284+ const selectedValues = config .select (' theme' , ' language' );
285+ console .log (selectedValues ); // Output: ['light', 'en']
286+
287+ // Retrieve state with names as tuples
288+ console .log (config .stateWithNames ); // Output: [['theme', 'light'], ['language', 'en'], ['notifications', true]]
289+
290+ // Reset the configuration state to its initial value
291+ config .reset ();
292+ console .log (config .toObject ()); // Output: { theme: 'dark', language: 'en', notifications: true }
262293```
263294
264295### ` BooleanState `
@@ -292,12 +323,6 @@ const activeState = new ActiveState();
292323activeState .deactivate ();
293324```
294325
295- ### ` Enum `
296-
297- ``` typescript
298- import { Enum } from ' @typescript-package/state' ;
299- ```
300-
301326### ` EnumState `
302327
303328``` typescript
@@ -354,30 +379,6 @@ connection.dispatch('connect');
354379console .log (connection .isConnected ()); // Output: true
355380```
356381
357- ### ` BooleanObjectState `
358-
359- ``` typescript
360- import { BooleanObjectState } from ' @typescript-package/state' ;
361- ```
362-
363- ### ` NamedObjectState `
364-
365- ``` typescript
366- import { NamedObjectState } from ' @typescript-package/state' ;
367- ```
368-
369- ### ` ObjectState `
370-
371- ``` typescript
372- import { ObjectState } from ' @typescript-package/state' ;
373- ```
374-
375- ### ` ImmutableState `
376-
377- ``` typescript
378- import { ImmutableState } from ' @typescript-package/state' ;
379- ```
380-
381382### ` NullState `
382383
383384``` typescript
0 commit comments