-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add loadable typecast for JsCallback arguments (#2225)
- Loading branch information
Showing
33 changed files
with
367 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atk4\Ui\Demos; | ||
|
||
use Atk4\Data\Model\UserAction; | ||
use Atk4\Ui\App; | ||
use Atk4\Ui\Form; | ||
|
||
/** @var App $app */ | ||
require_once __DIR__ . '/../init-app.php'; | ||
|
||
$country = new Country($app->db); | ||
|
||
$country->addUserAction('greetInteger', [ | ||
'appliesTo' => UserAction::APPLIES_TO_NO_RECORD, | ||
'args' => [ | ||
'foo' => [ | ||
'type' => 'integer', | ||
'required' => true, | ||
], | ||
], | ||
'callback' => static function (Country $entity, int $foo) { | ||
return 'Hello II ' . $foo; | ||
}, | ||
]); | ||
|
||
Form\Control\Line::addTo($app, ['action' => $country->getUserAction('greetInteger')]); | ||
|
||
$country->addUserAction('greetWrappedId', [ | ||
'appliesTo' => UserAction::APPLIES_TO_NO_RECORD, | ||
'args' => [ | ||
'foo' => [ | ||
'type' => WrappedIdType::NAME, | ||
'required' => true, | ||
], | ||
], | ||
'callback' => static function (Country $entity, WrappedId $foo) { | ||
return 'Hello III ' . $foo->getId(); | ||
}, | ||
]); | ||
|
||
Form\Control\Line::addTo($app, ['action' => $country->getUserAction('greetWrappedId')]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atk4\Ui\Js; | ||
|
||
use Atk4\Core\WarnDynamicPropertyTrait; | ||
|
||
class JsCallbackLoadableValue implements JsExpressionable | ||
{ | ||
use WarnDynamicPropertyTrait; | ||
|
||
private JsExpressionable $jsValue; | ||
|
||
/** @var \Closure(string): mixed */ | ||
private \Closure $loadTypecastFx; | ||
|
||
/** | ||
* @param \Closure(string): mixed $loadTypecastFx | ||
*/ | ||
public function __construct(?JsExpressionable $jsValue, \Closure $loadTypecastFx) | ||
{ | ||
if ($jsValue !== null) { | ||
$this->jsValue = $jsValue; | ||
} | ||
$this->loadTypecastFx = $loadTypecastFx; | ||
} | ||
|
||
#[\Override] | ||
public function jsRender(): string | ||
{ | ||
return $this->jsValue->jsRender(); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function typecastLoadValue(string $value) | ||
{ | ||
return ($this->loadTypecastFx)($value); | ||
} | ||
} |
Oops, something went wrong.