Skip to content

Commit

Permalink
Added hiddem input for the persisted viewmodel
Browse files Browse the repository at this point in the history
This way we can see if the browser supports reloading the hidden input fields. If this is not the case the History API will be used.
  • Loading branch information
GerardSmit committed Apr 29, 2019
1 parent c3151c0 commit 577c15b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 98 deletions.
Expand Up @@ -35,6 +35,11 @@ protected override void RenderControl(IHtmlWriter writer, IDotvvmRequestContext
writer.AddAttribute("value", serializedViewModel);
writer.RenderSelfClosingTag("input");


writer.AddAttribute("type", "hidden");
writer.AddAttribute("id", "__dot_persisted_viewmodel_root");
writer.RenderSelfClosingTag("input");

// init on load
writer.RenderBeginTag("script");
writer.WriteUnencodedText($@"
Expand Down
86 changes: 43 additions & 43 deletions src/DotVVM.Framework/Resources/Scripts/DotVVM.d.ts
Expand Up @@ -97,7 +97,7 @@ declare class DotvvmAfterPostBackEventArgs implements PostbackEventArgs {
postbackOptions: PostbackOptions;
serverResponseObject: any;
commandResult: any;
xhr: XMLHttpRequest | undefined;
xhr?: XMLHttpRequest | undefined;
isHandled: boolean;
wasInterrupted: boolean;
readonly postbackClientId: number;
Expand All @@ -117,7 +117,7 @@ declare class DotvvmSpaNavigatedEventArgs implements DotvvmEventArgs {
viewModel: any;
viewModelName: string;
serverResponseObject: any;
xhr: XMLHttpRequest | undefined;
xhr?: XMLHttpRequest | undefined;
isHandled: boolean;
constructor(viewModel: any, viewModelName: string, serverResponseObject: any, xhr?: XMLHttpRequest | undefined);
}
Expand All @@ -131,8 +131,8 @@ declare class DotvvmRedirectEventArgs implements DotvvmEventArgs {
}
declare class DotvvmFileUpload {
showUploadDialog(sender: HTMLElement): void;
private getIframe(sender);
private openUploadDialog(iframe);
private getIframe;
private openUploadDialog;
createUploadId(sender: HTMLElement, iframe: HTMLElement): void;
reportProgress(targetControlId: any, isBusy: boolean, progress: number, result: DotvvmFileUploadData[] | string): void;
}
Expand All @@ -155,7 +155,7 @@ declare class DotvvmFileSize {
FormattedText: KnockoutObservable<string>;
}
declare class DotvvmGlobalize {
private getGlobalize();
private getGlobalize;
format(format: string, ...values: any[]): string;
formatString(format: string, value: any): any;
parseDotvvmDate(value: string): Date | null;
Expand Down Expand Up @@ -192,10 +192,10 @@ interface AdditionalPostbackData {
}
declare class PostbackOptions {
readonly postbackId: number;
readonly sender: HTMLElement | undefined;
readonly sender?: HTMLElement | undefined;
readonly args: any[];
readonly viewModel: any;
readonly viewModelName: string | undefined;
readonly viewModel?: any;
readonly viewModelName?: string | undefined;
readonly additionalPostbackData: AdditionalPostbackData;
constructor(postbackId: number, sender?: HTMLElement | undefined, args?: any[], viewModel?: any, viewModelName?: string | undefined);
}
Expand Down Expand Up @@ -228,10 +228,10 @@ declare class DotvvmSerialization {
wrapObservable<T>(obj: T): KnockoutObservable<T>;
serialize(viewModel: any, opt?: ISerializationOptions): any;
validateType(value: any, type: string): boolean;
private findObject(obj, matcher);
private findObject;
flatSerialize(viewModel: any): any;
getPureObject(viewModel: any): {};
private pad(value, digits);
private pad;
serializeDate(date: string | Date | null, convertToUtc?: boolean): string | null;
}
interface Document {
Expand Down Expand Up @@ -285,7 +285,7 @@ declare class DotVVM {
private suppressOnDisabledElementHandler;
private beforePostbackEventPostbackHandler;
private isPostBackRunningHandler;
private createWindowSetTimeoutHandler(time);
private createWindowSetTimeoutHandler;
private windowSetTimeoutHandler;
private commonConcurrencyHandler;
private defaultConcurrencyPostbackHandler;
Expand All @@ -308,48 +308,48 @@ declare class DotVVM {
useHistoryApiSpaNavigation: boolean;
isPostbackRunning: KnockoutObservable<boolean>;
useHistoryApiViewModel: boolean;
private isBrowserReload();
private isBrowserReload;
init(viewModelName: string, culture: string): void;
private handlePopState(viewModelName, event, inSpaPage);
private handleHashChangeWithHistory(viewModelName, spaPlaceHolder, isInitialPageLoad);
private handleHashChange(viewModelName, spaPlaceHolder, isInitialPageLoad);
private persistViewModel(viewModelName);
private backUpPostBackConter();
private isPostBackStillActive(currentPostBackCounter);
private handlePopState;
private handleHashChangeWithHistory;
private handleHashChange;
private persistViewModel;
private backUpPostBackConter;
private isPostBackStillActive;
staticCommandPostback(viewModelName: string, sender: HTMLElement, command: string, args: any[], callback?: (_: any) => void, errorCallback?: (xhr: XMLHttpRequest, error?: any) => void): void;
private processPassedId(id, context);
private processPassedId;
protected getPostbackHandler(name: string): (options: any) => DotvvmPostbackHandler;
private isPostbackHandler(obj);
private isPostbackHandler;
findPostbackHandlers(knockoutContext: any, config: ClientFriendlyPostbackHandlerConfiguration[]): DotvvmPostbackHandler[];
private sortHandlers(handlers);
private applyPostbackHandlersCore(callback, options, handlers?);
private sortHandlers;
private applyPostbackHandlersCore;
applyPostbackHandlers(callback: (options: PostbackOptions) => Promise<PostbackCommitFunction | undefined>, sender: HTMLElement, handlers?: ClientFriendlyPostbackHandlerConfiguration[], args?: any[], context?: any, viewModel?: any, viewModelName?: string): Promise<DotvvmAfterPostBackEventArgs>;
postbackCore(options: PostbackOptions, path: string[], command: string, controlUniqueId: string, context: any, commandArgs?: any[]): Promise<() => Promise<DotvvmAfterPostBackEventArgs>>;
handleSpaNavigation(element: HTMLElement): boolean;
handleSpaNavigationCore(url: string | null): boolean;
postBack(viewModelName: string, sender: HTMLElement, path: string[], command: string, controlUniqueId: string, context?: any, handlers?: ClientFriendlyPostbackHandlerConfiguration[], commandArgs?: any[]): Promise<DotvvmAfterPostBackEventArgs>;
private loadResourceList(resources, callback);
private loadResourceElements(elements, offset, callback);
private getSpaPlaceHolder();
private navigateCore(viewModelName, url, handlePageNavigating?);
private handleRedirect(resultObject, viewModelName, replace?);
private performRedirect(url, replace, useHistoryApiSpaRedirect?);
private fixSpaUrlPrefix(url);
private removeVirtualDirectoryFromUrl(url, viewModelName);
private addLeadingSlash(url);
private concatUrl(url1, url2);
private loadResourceList;
private loadResourceElements;
private getSpaPlaceHolder;
private navigateCore;
private handleRedirect;
private performRedirect;
private fixSpaUrlPrefix;
private removeVirtualDirectoryFromUrl;
private addLeadingSlash;
private concatUrl;
patch(source: any, patch: any): any;
private updateDynamicPathFragments(context, path);
private postJSON(url, method, postData, success, error, preprocessRequest?);
private getJSON(url, method, spaPlaceHolderUniqueId, success, error);
private updateDynamicPathFragments;
private postJSON;
private getJSON;
getXHR(): XMLHttpRequest;
private cleanUpdatedControls(resultObject, updatedControls?);
private restoreUpdatedControls(resultObject, updatedControls, applyBindingsOnEachControl);
private cleanUpdatedControls;
private restoreUpdatedControls;
unwrapArrayExtension(array: any): any;
buildRouteUrl(routePath: string, params: any): string;
buildUrlSuffix(urlSuffix: string, query: any): string;
private isPostBackProhibited(element);
private addKnockoutBindingHandlers();
private isPostBackProhibited;
private addKnockoutBindingHandlers;
}
declare class DotvvmValidationContext {
valueToValidate: any;
Expand Down Expand Up @@ -455,7 +455,7 @@ declare class DotvvmValidation {
* Adds validation errors from the server to the appropriate arrays
*/
showValidationErrorsFromServer(args: DotvvmAfterPostBackEventArgs): void;
private addValidationError(validatedProperty, error);
private addValidationError;
}
declare var dotvvm: DotVVM;
declare class DotvvmEvaluator {
Expand All @@ -465,9 +465,9 @@ declare class DotvvmEvaluator {
tryEval(func: () => any): any;
isObservableArray(instance: any): instance is KnockoutObservableArray<any>;
wrapObservable(func: () => any, isArray?: boolean): KnockoutComputed<any>;
private updateObservable(getObservable, value);
private updateObservableArray(getObservableArray, fnName, args);
private getExpressionResult(func);
private updateObservable;
private updateObservableArray;
private getExpressionResult;
}
declare type ApiComputed<T> = KnockoutObservable<T | null> & {
refreshValue: (throwOnError?: boolean) => PromiseLike<any> | undefined;
Expand Down
71 changes: 40 additions & 31 deletions src/DotVVM.Framework/Resources/Scripts/DotVVM.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/DotVVM.Framework/Resources/Scripts/DotVVM.min.js

Large diffs are not rendered by default.

0 comments on commit 577c15b

Please sign in to comment.