Skip to content

Commit d77eb72

Browse files
committed
improve comments
1 parent 84c0cfe commit d77eb72

File tree

1 file changed

+25
-29
lines changed
  • src/plugins/kibana_utils/public/store

1 file changed

+25
-29
lines changed

src/plugins/kibana_utils/public/store/sync.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import { createUrlControls, getStateFromUrl, IUrlControls, setStateToUrl } from
2323

2424
/**
2525
* Configuration of StateSync utility
26-
* State - the interface of the form of application provided state
27-
* StorageState - interface of the transformed State which will be serialised into storage
26+
* State - interface for application provided state
27+
* StorageState - interface for the transformed State which will be passed into SyncStrategy for serialising and persisting
2828
* (see toStorageMapper, fromStorageMapper)
2929
*/
3030
export interface IStateSyncConfig<
@@ -33,21 +33,21 @@ export interface IStateSyncConfig<
3333
> {
3434
/**
3535
* Storage key to use for syncing,
36-
* e.g. syncKey '_a' should be synced state to ?_a query param
36+
* e.g. syncKey '_a' should sync state to ?_a query param
3737
*/
3838
syncKey: string;
3939
/**
4040
* Store to keep in sync with storage, have to implement IStore interface
4141
* The idea is that ./store/create_store.ts should be used as a state container,
42-
* but it is also possible to implement own container for advanced use cases
42+
* but it is also possible to implement own custom container for advanced use cases
4343
*/
4444
store: IStore<State>;
4545
/**
4646
* Sync strategy to use,
47-
* Is responsible for where to put to / where to get from the stored state
48-
* 2 strategies available now, which replicate what State (AppState, GlobalState) implemented:
47+
* Sync strategy is responsible for serialising / deserialising and persisting / retrieving stored state
48+
* 2 strategies available now out of the box, which replicate what State (AppState, GlobalState) implemented:
4949
*
50-
* SyncStrategy.Url: the same as old persisting of expanded state in rison format to url
50+
* SyncStrategy.Url: the same as old persisting of expanded state in rison format to the url
5151
* SyncStrategy.HashedUrl: the same as old persisting of hashed state using sessionStorage for storing expanded state
5252
*
5353
* Possible to provide own custom SyncStrategy by implementing ISyncStrategy
@@ -60,15 +60,15 @@ export interface IStateSyncConfig<
6060
* These mappers are needed to transform application state to a different shape we want to store
6161
* Some use cases:
6262
*
63-
* 1. Want to pick some specific parts of State to store.
63+
* 1. Pick some specific parts of the state to persist.
6464
*
6565
* Having state in shape of:
6666
* type State = {a: string, b: string};
6767
*
6868
* Passing toStorageMapper as:
6969
* toStorageMapper: (state) => ({b: state.b})
7070
*
71-
* Will result in storing only b
71+
* Will result in storing only `b`
7272
*
7373
* 2. Original state keys are too long and we want to give them a shorter name to persist in the url/storage
7474
*
@@ -85,9 +85,9 @@ export interface IStateSyncConfig<
8585
*
8686
* 3. Use different sync strategies for different state slices
8787
*
88-
* We could have multiple SyncStorageConfigs for a State container,
88+
* We could have multiple SyncStorageConfigs for a state container,
8989
* These mappers allow to pick slices of state we want to use in this particular configuration.
90-
* So we can setup a slice of state to be stored in the URL as expanded state
90+
* For example: we can setup a slice of state to be stored in the URL as expanded state
9191
* and then different slice of the same state as HashedURL (just by using different strategies).
9292
*
9393
* 4. Backward compatibility
@@ -104,22 +104,20 @@ export interface IStateSyncConfig<
104104
fromStorageMapper?: (storageState: StorageState) => Partial<State>;
105105

106106
/**
107-
* On app start during StateSync util setup,
108-
* Storage state and Applications's default state could be out of sync.
107+
* During app bootstrap we could have default app state and data in storage to be out of sync,
108+
* initialTruthSource indicates who's values to consider as source of truth
109109
*
110-
* initialTruthSource indicates who's values consider as source of truth
111-
*
112-
* InitialTruthSource.State - Application state take priority over storage state
110+
* InitialTruthSource.Store - Application state take priority over storage state
113111
* InitialTruthSource.Storage (default) - Storage state take priority over Application state
114112
* InitialTruthSource.None - skip initial syncing do nothing
115113
*/
116114
initialTruthSource?: InitialTruthSource;
117115
}
118116

119117
/**
120-
* To use StateSync util application have to pass state in the shape of following interface
121-
* The idea is that ./store/create_store.ts should be used as state container,
122-
* but it is also possible to implement own container for advanced use cases
118+
* To use stateSync util application have to pass state container which implements IStore interface.
119+
* The idea is that ./store/create_store.ts should be used as a state container by default,
120+
* but it is also possible to implement own custom container for advanced use cases
123121
*/
124122
export type BaseState = Record<string, unknown>;
125123
export interface IStore<State extends BaseState = BaseState> {
@@ -129,12 +127,10 @@ export interface IStore<State extends BaseState = BaseState> {
129127
}
130128

131129
/**
132-
* On app start during initial setup,
133-
* Storage state and applications's default state could be out of sync.
134-
*
135-
* initialTruthSource indicates who's values consider as source of truth
130+
* During app bootstrap we could have default app state and data in storage to be out of sync,
131+
* initialTruthSource indicates who's values to consider as source of truth
136132
*
137-
* InitialTruthSource.State - Application state take priority over storage state
133+
* InitialTruthSource.Store - Application state take priority over storage state
138134
* InitialTruthSource.Storage (default) - Storage state take priority over Application state
139135
* InitialTruthSource.None - skip initial syncing do nothing
140136
*/
@@ -145,10 +141,10 @@ export enum InitialTruthSource {
145141
}
146142

147143
/**
148-
* Sync strategy is responsible for where to put to / where to get from the stored state
149-
* 2 strategies available now, which replicate what State (AppState, GlobalState) implemented:
144+
* Sync strategy is responsible for serialising / deserialising and persisting / retrieving stored state
145+
* 2 strategies available now out of the box, which replicate what State (AppState, GlobalState) implemented:
150146
*
151-
* SyncStrategy.Url: the same as old persisting of expanded state in rison format to url
147+
* SyncStrategy.Url: the same as old persisting of expanded state in rison format to the url
152148
* SyncStrategy.HashedUrl: the same as old persisting of hashed state using sessionStorage for storing expanded state
153149
*
154150
* Possible to provide own custom SyncStrategy by implementing ISyncStrategy
@@ -163,8 +159,8 @@ export enum SyncStrategy {
163159
/**
164160
* Any SyncStrategy have to implement ISyncStrategy interface
165161
* SyncStrategy is responsible for:
166-
* state serialisation / deserialization
167-
* persisting to and retrieving from storage
162+
* * state serialisation / deserialization
163+
* * persisting to and retrieving from storage
168164
*
169165
* For an example take a look at already implemented URL sync strategies
170166
*/

0 commit comments

Comments
 (0)