dotvvm-types 4.3.4 → 4.3.6
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 +48 -5
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -212,6 +212,8 @@ declare module "validation/error" {
|
|
|
212
212
|
}
|
|
213
213
|
declare module "state-manager" {
|
|
214
214
|
import { DotvvmEvent } from "events";
|
|
215
|
+
import { ValidationError } from "validation/error";
|
|
216
|
+
import { errorsSymbol } from "validation/common";
|
|
215
217
|
export const currentStateSymbol: unique symbol;
|
|
216
218
|
export const notifySymbol: unique symbol;
|
|
217
219
|
export const lastSetErrorSymbol: unique symbol;
|
|
@@ -224,29 +226,69 @@ declare module "state-manager" {
|
|
|
224
226
|
[currentStateSymbol]: T;
|
|
225
227
|
[updateSymbol]?: UpdateDispatcher<T>;
|
|
226
228
|
};
|
|
229
|
+
/** Manages the consistency of DotVVM immutable ViewModel state object with the knockout observables.
|
|
230
|
+
* Knockout observables are by-default updated asynchronously after a state change, but the synchronization can be forced by calling `doUpdateNow`.
|
|
231
|
+
* The newState event is also called asynchronously right before the knockout observables are updated.
|
|
232
|
+
* Changes from observables to state are immediate.
|
|
233
|
+
*/
|
|
227
234
|
export class StateManager<TViewModel extends {
|
|
228
235
|
$type?: TypeDefinition;
|
|
229
|
-
}> {
|
|
236
|
+
}> implements DotvvmStateContainer<TViewModel> {
|
|
230
237
|
stateUpdateEvent: DotvvmEvent<DeepReadonly<TViewModel>>;
|
|
238
|
+
/** The knockout observable containing the root objects, equivalent to `dotvvm.viewModels.root.viewModel` */
|
|
231
239
|
readonly stateObservable: DeepKnockoutObservable<TViewModel>;
|
|
232
240
|
private _state;
|
|
241
|
+
/** Returns the current */
|
|
233
242
|
get state(): DeepReadonly<TViewModel>;
|
|
234
243
|
private _isDirty;
|
|
244
|
+
/** Indicates whether there is a pending update of the knockout observables. */
|
|
235
245
|
get isDirty(): boolean;
|
|
236
246
|
private _currentFrameNumber;
|
|
237
247
|
constructor(initialState: DeepReadonly<TViewModel>, stateUpdateEvent: DotvvmEvent<DeepReadonly<TViewModel>>);
|
|
238
|
-
dispatchUpdate
|
|
248
|
+
private dispatchUpdate;
|
|
249
|
+
/** Performs a synchronous update of knockout observables with the data currently stored in `state`.
|
|
250
|
+
* Consequently, if ko.options.deferUpdates is false (default), the UI will be updated immediately.
|
|
251
|
+
* If ko.options.deferUpdates is true, the UI can be manually updated by also calling the `ko.tasks.runEarly()` function. */
|
|
239
252
|
doUpdateNow(): void;
|
|
240
253
|
private rerender;
|
|
254
|
+
/** Sets a new view model state, after checking its type compatibility and possibly performing implicit conversions.
|
|
255
|
+
* Only the changed objects are re-checked and updated in the knockout observables.
|
|
256
|
+
* It is therefore recommended to clone only the changed parts of the view model using the `{... x, ChangedProp: 1 }` syntax.
|
|
257
|
+
* 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.
|
|
258
|
+
*
|
|
259
|
+
* @throws CoerceError if the new state has incompatible type.
|
|
260
|
+
* @returns The type-coerced version of the new state. */
|
|
241
261
|
setState(newState: DeepReadonly<TViewModel>): DeepReadonly<TViewModel>;
|
|
242
|
-
|
|
243
|
-
|
|
262
|
+
/** Applies a patch to the current view model state.
|
|
263
|
+
* @throws CoerceError if the new state has incompatible type.
|
|
264
|
+
* @returns The type-coerced version of the new state. */
|
|
265
|
+
patchState(patch: DeepReadonly<DeepPartial<TViewModel>>): DeepReadonly<TViewModel>;
|
|
266
|
+
/** Updates the view model state using the provided `State => State` function.
|
|
267
|
+
* @throws CoerceError if the new state has incompatible type.
|
|
268
|
+
* @returns The type-coerced version of the new state. */
|
|
269
|
+
updateState(updater: StateUpdate<TViewModel>): DeepReadonly<TViewModel>;
|
|
270
|
+
/** @deprecated Use updateState method instead */
|
|
271
|
+
update: UpdateDispatcher<TViewModel>;
|
|
272
|
+
}
|
|
273
|
+
class FakeObservableObject<T extends object> implements UpdatableObjectExtensions<T> {
|
|
274
|
+
[currentStateSymbol]: T;
|
|
275
|
+
[errorsSymbol]: Array<ValidationError>;
|
|
276
|
+
[updateSymbol]: UpdateDispatcher<T>;
|
|
277
|
+
[notifySymbol](newValue: T): void;
|
|
278
|
+
[internalPropCache]: {
|
|
279
|
+
[name: string]: (KnockoutObservable<any> & UpdatableObjectExtensions<any>) | null;
|
|
280
|
+
};
|
|
281
|
+
[updatePropertySymbol](propName: keyof DeepReadonly<T>, valUpdate: StateUpdate<any>): void;
|
|
282
|
+
constructor(initialValue: T, getter: () => DeepReadonly<T> | undefined, updater: UpdateDispatcher<T>, typeId: TypeDefinition, typeInfo: ObjectTypeMetadata | DynamicTypeMetadata | undefined, additionalProperties: string[]);
|
|
244
283
|
}
|
|
284
|
+
export function isDotvvmObservable(obj: any): obj is DotvvmObservable<any>;
|
|
285
|
+
export function isFakeObservableObject(obj: any): obj is FakeObservableObject<any>;
|
|
245
286
|
/**
|
|
246
287
|
* Recursively unwraps knockout observables from the object / array hierarchy. When nothing needs to be unwrapped, the original object is returned.
|
|
247
288
|
* @param allowStateUnwrap Allows accessing [currentStateSymbol], which makes it faster, but doesn't register in the knockout dependency tracker
|
|
289
|
+
* @param preferStateAccess Also allows accessing observable.state, which also doesn't register in the knockout dependency tracker, but returns an realtime updated value directly from dotvvm.state
|
|
248
290
|
*/
|
|
249
|
-
export function unmapKnockoutObservables(viewModel: any, allowStateUnwrap?: boolean): any;
|
|
291
|
+
export function unmapKnockoutObservables(viewModel: any, allowStateUnwrap?: boolean, preferStateAccess?: boolean): any;
|
|
250
292
|
}
|
|
251
293
|
declare module "serialization/deserialize" {
|
|
252
294
|
export function deserialize(viewModel: any, target?: any, deserializeAll?: boolean): any;
|
|
@@ -887,6 +929,7 @@ declare module "dotvvm-root" {
|
|
|
887
929
|
patchState(a: any): void;
|
|
888
930
|
setState(a: any): void;
|
|
889
931
|
updateState(updateFunction: StateUpdate<any>): void;
|
|
932
|
+
readonly rootStateManager: StateManager<RootViewModel>;
|
|
890
933
|
viewModelObservables: {
|
|
891
934
|
readonly root: KnockoutObservable<DeepKnockoutObservableObject<RootViewModel>>;
|
|
892
935
|
};
|