dotvvm-types 4.3.4 → 4.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/types/index.d.ts +32 -4
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -224,24 +224,51 @@ declare module "state-manager" {
|
|
|
224
224
|
[currentStateSymbol]: T;
|
|
225
225
|
[updateSymbol]?: UpdateDispatcher<T>;
|
|
226
226
|
};
|
|
227
|
+
/** Manages the consistency of DotVVM immutable ViewModel state object with the knockout observables.
|
|
228
|
+
* Knockout observables are by-default updated asynchronously after a state change, but the synchronization can be forced by calling `doUpdateNow`.
|
|
229
|
+
* The newState event is also called asynchronously right before the knockout observables are updated.
|
|
230
|
+
* Changes from observables to state are immediate.
|
|
231
|
+
*/
|
|
227
232
|
export class StateManager<TViewModel extends {
|
|
228
233
|
$type?: TypeDefinition;
|
|
229
|
-
}> {
|
|
234
|
+
}> implements DotvvmStateContainer<TViewModel> {
|
|
230
235
|
stateUpdateEvent: DotvvmEvent<DeepReadonly<TViewModel>>;
|
|
236
|
+
/** The knockout observable containing the root objects, equivalent to `dotvvm.viewModels.root.viewModel` */
|
|
231
237
|
readonly stateObservable: DeepKnockoutObservable<TViewModel>;
|
|
232
238
|
private _state;
|
|
239
|
+
/** Returns the current */
|
|
233
240
|
get state(): DeepReadonly<TViewModel>;
|
|
234
241
|
private _isDirty;
|
|
242
|
+
/** Indicates whether there is a pending update of the knockout observables. */
|
|
235
243
|
get isDirty(): boolean;
|
|
236
244
|
private _currentFrameNumber;
|
|
237
245
|
constructor(initialState: DeepReadonly<TViewModel>, stateUpdateEvent: DotvvmEvent<DeepReadonly<TViewModel>>);
|
|
238
|
-
dispatchUpdate
|
|
246
|
+
private dispatchUpdate;
|
|
247
|
+
/** Performs a synchronous update of knockout observables with the data currently stored in `state`.
|
|
248
|
+
* Consequently, if ko.options.deferUpdates is false (default), the UI will be updated immediately.
|
|
249
|
+
* If ko.options.deferUpdates is true, the UI can be manually updated by also calling the `ko.tasks.runEarly()` function. */
|
|
239
250
|
doUpdateNow(): void;
|
|
240
251
|
private rerender;
|
|
252
|
+
/** Sets a new view model state, after checking its type compatibility and possibly performing implicit conversions.
|
|
253
|
+
* Only the changed objects are re-checked and updated in the knockout observables.
|
|
254
|
+
* It is therefore recommended to clone only the changed parts of the view model using the `{... x, ChangedProp: 1 }` syntax.
|
|
255
|
+
* In the rarely occuring complex cases where this is difficult, you can use `structuredClone` to obtain a writable clone of some part of the viewmodel.
|
|
256
|
+
*
|
|
257
|
+
* @throws CoerceError if the new state has incompatible type.
|
|
258
|
+
* @returns The type-coerced version of the new state. */
|
|
241
259
|
setState(newState: DeepReadonly<TViewModel>): DeepReadonly<TViewModel>;
|
|
242
|
-
|
|
243
|
-
|
|
260
|
+
/** Applies a patch to the current view model state.
|
|
261
|
+
* @throws CoerceError if the new state has incompatible type.
|
|
262
|
+
* @returns The type-coerced version of the new state. */
|
|
263
|
+
patchState(patch: DeepReadonly<DeepPartial<TViewModel>>): DeepReadonly<TViewModel>;
|
|
264
|
+
/** Updates the view model state using the provided `State => State` function.
|
|
265
|
+
* @throws CoerceError if the new state has incompatible type.
|
|
266
|
+
* @returns The type-coerced version of the new state. */
|
|
267
|
+
updateState(updater: StateUpdate<TViewModel>): DeepReadonly<TViewModel>;
|
|
268
|
+
/** @deprecated Use updateState method instead */
|
|
269
|
+
update: UpdateDispatcher<TViewModel>;
|
|
244
270
|
}
|
|
271
|
+
export function isDotvvmObservable(obj: any): obj is DotvvmObservable<any>;
|
|
245
272
|
/**
|
|
246
273
|
* Recursively unwraps knockout observables from the object / array hierarchy. When nothing needs to be unwrapped, the original object is returned.
|
|
247
274
|
* @param allowStateUnwrap Allows accessing [currentStateSymbol], which makes it faster, but doesn't register in the knockout dependency tracker
|
|
@@ -887,6 +914,7 @@ declare module "dotvvm-root" {
|
|
|
887
914
|
patchState(a: any): void;
|
|
888
915
|
setState(a: any): void;
|
|
889
916
|
updateState(updateFunction: StateUpdate<any>): void;
|
|
917
|
+
readonly rootStateManager: StateManager<RootViewModel>;
|
|
890
918
|
viewModelObservables: {
|
|
891
919
|
readonly root: KnockoutObservable<DeepKnockoutObservableObject<RootViewModel>>;
|
|
892
920
|
};
|