Skip to content

Commit

Permalink
collect running callback triggers directly from render tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jul 24, 2021
1 parent baa3bdc commit 077d40e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ protected function init(): void
public function setUrlTrigger(string $trigger = null)
{
$this->urlTrigger = $trigger ?: $this->name;

$this->getOwner()->stickyGet(self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger);
}

public function getUrlTrigger(): string
Expand Down
26 changes: 24 additions & 2 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public function removeAttr($property)
*/
public function jsUrl($page = [])
{
return $this->getApp()->jsUrl($page, false, $this->_getStickyArgs());
return $this->getApp()->jsUrl($page, false, array_merge($this->getRunningCallbackArgs(false, $page), $this->_getStickyArgs()));
}

/**
Expand All @@ -613,7 +613,29 @@ public function jsUrl($page = [])
*/
public function url($page = [])
{
return $this->getApp()->url($page, false, $this->_getStickyArgs());
return $this->getApp()->url($page, false, array_merge($this->getRunningCallbackArgs(false, $page), $this->_getStickyArgs()));
}

protected function getRunningCallbackArgs(bool $isTerminated, $page): array
{
$args = [];
foreach ($this->elements as $v) {
if ($v instanceof Callback && $v->isTriggered() && $v->canTrigger()) {
if (($page[Callback::URL_QUERY_TARGET] ?? null) === $v->getUrlTrigger()) {
$isTerminated = true;
}

if ($isTerminated) {
$args[Callback::URL_QUERY_TRIGGER_PREFIX . $v->getUrlTrigger()] = $v->getTriggeredValue();
}
}
}

if ($this->issetOwner() && $this->getOwner() instanceof self) {
$args = array_merge($this->getOwner()->getRunningCallbackArgs($isTerminated, $page), $args);
}

return $args;
}

/**
Expand Down

0 comments on commit 077d40e

Please sign in to comment.