Skip to content

Commit

Permalink
JsCallback always terminate with success
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Mar 31, 2024
1 parent b3a08e5 commit 0453b60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/JsCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,13 @@ public function set($fx = null, $args = null)
/**
* A proper way to finish execution of AJAX response. Generates JSON
* which is returned to frontend.
*
* @param ($success is true ? null : string) $msg General message, typically won't be displayed
* @param bool $success Was request successful or not
*/
public function terminateAjaxIfCanTerminate(JsBlock $ajaxec, $msg = null, bool $success = true): void
public function terminateAjaxIfCanTerminate(JsBlock $ajaxec): void
{
$data = ['success' => $success];
if (!$success) {
$data['message'] = $msg;
}
$data['atkjs'] = $ajaxec->jsRender();
$data = [
'success' => true,
'atkjs' => $ajaxec->jsRender(),
];

if ($this->canTerminate()) {
$this->getApp()->terminateJson($data);
Expand Down
8 changes: 4 additions & 4 deletions src/JsSse.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ protected function initSse(): void
/**
* Sending an SSE action.
*/
public function send(JsExpressionable $action, bool $success = true): void
public function send(JsExpressionable $action): void
{
$ajaxec = $this->getAjaxec($action);
$this->sendEvent(
'',
$this->getApp()->encodeJson([
'success' => $success,
'success' => true,
'atkjs' => $ajaxec->jsRender(),
]),
'atkSseAction'
Expand All @@ -100,14 +100,14 @@ public function send(JsExpressionable $action, bool $success = true): void
* @return never
*/
#[\Override]
public function terminateAjaxIfCanTerminate(JsBlock $ajaxec, $msg = null, bool $success = true): void
public function terminateAjaxIfCanTerminate(JsBlock $ajaxec): void
{
$ajaxecStr = $ajaxec->jsRender();
if ($ajaxecStr !== '') {
$this->sendEvent(
'',
$this->getApp()->encodeJson([
'success' => $success,
'success' => true,
'atkjs' => $ajaxecStr,
]),
'atkSseAction'
Expand Down

0 comments on commit 0453b60

Please sign in to comment.