dotvvm-types 4.2.0-preview05-final → 4.2.0-preview06-final

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types/index.d.ts +26 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotvvm-types",
3
- "version": "4.2.0-preview05-final",
3
+ "version": "4.2.0-preview06-final",
4
4
  "description": "MVVM framework for ASP.NET",
5
5
  "types": "./types/index.d.ts",
6
6
  "repository": {
package/types/index.d.ts CHANGED
@@ -70,6 +70,7 @@ declare module "utils/objects" {
70
70
  (o: object): string[];
71
71
  (o: {}): string[];
72
72
  };
73
+ export function defineConstantProperty(obj: any, name: string, value: any): void;
73
74
  }
74
75
  declare module "metadata/typeMap" {
75
76
  export function getTypeInfo(typeId: string | object): TypeMetadata;
@@ -324,9 +325,13 @@ declare module "viewModules/viewModuleManager" {
324
325
  [name: string]: (...args: any[]) => Promise<any>;
325
326
  };
326
327
  module: any;
328
+ setState: (state: any) => void;
329
+ patchState: (state: any) => void;
330
+ updateState: (updateFunction: StateUpdate<any>) => void;
331
+ state: any;
327
332
  constructor(moduleName: string, elements: HTMLElement[], properties: {
328
333
  [name: string]: any;
329
- });
334
+ }, viewModel: DotvvmObservable<any>);
330
335
  registerNamedCommand: (name: string, command: (...args: any[]) => Promise<any>) => void;
331
336
  unregisterNamedCommand: (name: string) => void;
332
337
  }
@@ -850,6 +855,8 @@ declare module "dotvvm-root" {
850
855
  };
851
856
  readonly state: Readonly<RootViewModel>;
852
857
  patchState(a: any): void;
858
+ setState(a: any): void;
859
+ updateState(updateFunction: StateUpdate<any>): void;
853
860
  viewModelObservables: {
854
861
  readonly root: KnockoutObservable<DeepKnockoutObservableObject<RootViewModel>>;
855
862
  };
@@ -888,7 +895,7 @@ declare module "dotvvm-root" {
888
895
  global {
889
896
  interface DotvvmGlobalExtensions {
890
897
  }
891
- type DotvvmGlobal = DotvvmGlobalExtensions & typeof dotvvmExports & {
898
+ type DotvvmGlobal = DotvvmGlobalExtensions & typeof dotvvmExports & DotvvmStateContainer<any> & {
892
899
  debug?: true;
893
900
  isSpaReady?: typeof isSpaReady;
894
901
  handleSpaNavigation?: typeof handleSpaNavigation;
@@ -1080,26 +1087,30 @@ declare type DeepPartial<T> = T extends object ? {
1080
1087
  declare type DeepReadonly<T> = T extends TypeDefinition ? T : T extends (infer R)[] ? readonly DeepReadonly<R>[] : T extends object ? {
1081
1088
  readonly [P in keyof T]: DeepReadonly<T[P]>;
1082
1089
  } : T;
1083
- /** Knockout observable that is found in the DotVVM ViewModel - all nested objects and arrays are also observable + it has some helper functions (state, patchState, ...) */
1084
- declare type DotvvmObservable<T> = DeepKnockoutObservable<T> & {
1085
- /** A property, returns latest state from dotvvm.state. It does not contain any knockout observable and does not have any propagation delay, as the value in the observable */
1090
+ declare type DotvvmStateContainer<T> = {
1091
+ /** A property, returns latest state from dotvvm.state. It does not contain any knockout observable and does not have any propagation delay, as the value in the ko.observables */
1086
1092
  readonly state: DeepReadonly<T>;
1087
1093
  /** Sets new state directly into the dotvvm.state.
1088
- * Note that the value arrives into the observable itself asynchronously, so there might be slight delay */
1094
+ * Note that the value arrives into the ko.observables asynchronously, so there might be slight delay */
1089
1095
  readonly setState: (newState: DeepReadonly<T>) => void;
1090
1096
  /** Patches the current state and sets it into dotvvm.state.
1091
1097
  * Compared to setState, when property does not exist in the patch parameter, the old value from state is used.
1092
- * Note that the value arrives into the observable itself asynchronously, so there might be slight delay
1098
+ * Note that the value arrives into the ko.observables asynchronously, so there might be slight delay
1093
1099
  * @example observable.patchState({ Prop2: 0 }) // Only must be specified, although Prop1 also exists and is required */
1094
1100
  readonly patchState: (patch: DeepReadonly<DeepPartial<T>>) => void;
1095
1101
  /** Dispatches update of the state.
1096
- * Note that the value arrives into the observable itself asynchronously, so there might be slight delay
1097
- * @example observable.updater(state => [ ...state, newElement ]) // This appends an element to an (observable) array
1098
- * @example observable.updater(state => state + 1) // Increments the value by one
1099
- * @example observable.updater(state => ({ ...state, MyProperty: state.MyProperty + 1 })) // Increments the property MyProperty by one
1102
+ * Note that the value arrives into the ko.observables asynchronously, so there might be slight delay
1103
+ * @example observable.updateState(state => [ ...state, newElement ]) // This appends an element to an (observable) array
1104
+ * @example observable.updateState(state => state + 1) // Increments the value by one
1105
+ * @example observable.updateState(state => ({ ...state, MyProperty: state.MyProperty + 1 })) // Increments the property MyProperty by one
1100
1106
  */
1101
- readonly updater: UpdateDispatcher<T>;
1107
+ readonly updateState: UpdateDispatcher<T>;
1102
1108
  };
1109
+ /** Knockout observable that is found in the DotVVM ViewModel - all nested objects and arrays are also observable + it has some helper functions (state, patchState, ...) */
1110
+ declare type DotvvmObservable<T> = DeepKnockoutObservable<T> & {
1111
+ /** @deprecated Use updateState instead */
1112
+ readonly updater: UpdateDispatcher<T>;
1113
+ } & DotvvmStateContainer<T>;
1103
1114
  declare type RootViewModel = {
1104
1115
  $type: string;
1105
1116
  $csrfToken?: string;
@@ -1199,7 +1210,7 @@ declare type DotvvmViewModule = {
1199
1210
  $dispose?: (context: any) => void;
1200
1211
  [commandName: DotvvmViewModuleCommandName]: (...args: any[]) => Promise<any> | any;
1201
1212
  };
1202
- declare type DotvvmModuleContext = {
1213
+ declare type DotvvmModuleContext<TViewModelType = any> = {
1203
1214
  /** Name of the resource defining the view module */
1204
1215
  moduleName: string;
1205
1216
  /** Instance of the view module */
@@ -1208,10 +1219,10 @@ declare type DotvvmModuleContext = {
1208
1219
  elements: HTMLElement[];
1209
1220
  /** Properties of the markup control which were sent to the client */
1210
1221
  properties: {
1211
- [name: string]: any;
1222
+ [name: string]: DotvvmObservable<any>;
1212
1223
  };
1213
1224
  /** <dot:NamedCommand /> declared in the dothtml/dotcontrol view. */
1214
1225
  namedCommands: {
1215
1226
  [name: string]: (...args: any[]) => Promise<any>;
1216
1227
  };
1217
- };
1228
+ } & DotvvmStateContainer<TViewModelType>;