New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring and fixes in postback pipeline #885
Conversation
The postbacks are disabled on SPA Navigation or on redirect. When postbacks are disabled, postback handlers and commit function throws an error
…tartedEventHandler from globalPostbackHandlers collections - build fix
…events-refactoring
…ling for postbacks and static commands
handled: boolean | ||
} | ||
|
||
type DotvvmBeforePostBackEventArgs = PostbackEventArgs & { | ||
type DotvvmBeforePostBackEventArgs = PostbackOptions & { | ||
cancel: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the cancel
field, you can use postback handler to cancel a postback
/** Whether the new url should replace the current url in the browsing history */ | ||
readonly response?: Response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misplaced comment 🙃
} | ||
|
||
type DotvvmStaticCommandMethodEventArgs = PostbackOptions & { | ||
readonly command: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd not include the command in the args. It is an encrypted string that may change at any moment, I doubt there is any legit use case for it.
// trigger postbackRejected event | ||
const postbackRejectedEventArgs: DotvvmPostbackRejectedEventArgs = { | ||
...options, | ||
serverResponseObject, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant, when the postback is interrupted, there is no serverResponseObject
and response
} | ||
function shouldTriggerErrorEvent(err: DotvvmPostbackError) { | ||
return !isInterruptingErrorReason(err) && | ||
(err.reason.type == "network" || err.reason.type == "serverError"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify to err.reason.type == "network" || err.reason.type == "serverError"
serverResponseObject, | ||
response: (err.reason as any).response, | ||
error: err, | ||
wasInterrupted: isInterruptingErrorReason(err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always false.
serverResponseObject, | ||
response: (err.reason as any).response, | ||
error: err, | ||
wasInterrupted: isInterruptingErrorReason(err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always false.
type DotvvmAfterPostBackEventArgs = PostbackEventArgs & { | ||
handled: boolean | ||
|
||
type DotvvmAfterPostBackEventArgs = PostbackOptions & { | ||
/** Set to true in case the postback did not finish and it was cancelled by an event or a postback handler */ | ||
readonly wasInterrupted: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd chage it to wasInterrupted?: true
, so we don't have to include it on all the places where it's false.
action(); | ||
|
||
const currentErrorsCount = allErrors.length; | ||
if (originalErrorsCount === 0 && currentErrorsCount === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer ==
everywhere when the types match.
StaticCommand events: command renamed to methodId, args renamed to methodArgs
This PR contains several things: