Skip to content

Commit

Permalink
Unimplement JsExpressionable from JsCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 21, 2022
1 parent c834d60 commit 523c3b4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/callbacks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ When you trigger callback, you'll see the output::
{"success": true, "message": "Success", "eval": "alert(\"ok\")"}

This is how JsCallback renders actions and sends them back to the browser. In order to retrieve and execute actions,
you'll need a JavaScript routine. Luckily JsCallback also implements JsExpressionable, so it, in itself is an action.
you'll need a JavaScript routine. Luckily JsCallback can be passed to :php:meth:`View::on()` as an JS action.

Let me try this again. JsCallback is an :ref:`js_action` which will execute request towards a callback-URL that will
execute PHP method returning one or more :ref:`js_action` which will be received and executed by the original action.
Expand Down
2 changes: 1 addition & 1 deletion src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function set($fx = null, $event = null)
*/
public function jsExecute()
{
return $this->sse;
return $this->sse->getJsCallback();
}

private function escapeOutputHtml(string $message): string
Expand Down
6 changes: 3 additions & 3 deletions src/JsCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Atk4\Ui;

class JsCallback extends Callback implements JsExpressionable
class JsCallback extends Callback
{
/** @var array Holds information about arguments passed in to the callback. */
public $args = [];
Expand Down Expand Up @@ -47,7 +47,7 @@ protected function flattenArray(array $response): array
return $res;
}

public function jsRender(): string
public function getJsCallback(): JsExpression
{
$this->getApp(); // assert has App

Expand All @@ -57,7 +57,7 @@ public function jsRender(): string
'confirm' => $this->confirm,
'apiConfig' => $this->apiConfig,
'storeName' => $this->storeName,
])->jsRender();
]);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,9 @@ public function on(string $event, $selector = null, $action = null, array $defau
return $action($chain, ...$args);
}, $arguments);

$actions[] = $cb;
$actions[] = $cb->getJsCallback();
} elseif ($action instanceof JsCallback) {
$actions[] = $action->getJsCallback();
} elseif ($action instanceof UserAction\ExecutorInterface || $action instanceof Model\UserAction) {
// Setup UserAction executor.
$ex = $action instanceof Model\UserAction ? $this->getExecutorFactory()->create($action, $this) : $action;
Expand All @@ -1044,7 +1046,7 @@ public function on(string $event, $selector = null, $action = null, array $defau
if ($defaults['apiConfig'] ?? null) {
$ex->apiConfig = $defaults['apiConfig'];
}
$actions[] = $ex;
$actions[] = $ex->getJsCallback();
$ex->executeModelAction($arguments);
} else {
throw new Exception('Executor must be of type UserAction\JsCallbackExecutor or extend View and implement UserAction\JsExecutorInterface');
Expand Down

0 comments on commit 523c3b4

Please sign in to comment.