-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "always" props using new
Inertia::always()
wrapper (#627)
* `AlwaysProp` implementation * make `always` accept any param type * resolve bindings on `AlwaysProp` invoke * resolve callables in `AlwaysProp` * Update "always" types in facade * Update changelog --------- Co-authored-by: Jonathan Reinink <[email protected]>
- Loading branch information
Showing
11 changed files
with
140 additions
and
124 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,24 @@ | ||
<?php | ||
|
||
namespace Inertia; | ||
|
||
use Illuminate\Support\Facades\App; | ||
|
||
class AlwaysProp | ||
{ | ||
/** @var mixed */ | ||
protected $value; | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __construct($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function __invoke() | ||
{ | ||
return is_callable($this->value) ? App::call($this->value) : $this->value; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace Inertia\Tests; | ||
|
||
use Illuminate\Http\Request; | ||
use Inertia\AlwaysProp; | ||
|
||
class AlwaysPropTest extends TestCase | ||
{ | ||
public function test_can_invoke(): void | ||
{ | ||
$alwaysProp = new AlwaysProp(function () { | ||
return 'An always value'; | ||
}); | ||
|
||
$this->assertSame('An always value', $alwaysProp()); | ||
} | ||
|
||
public function test_can_accept_scalar_values(): void | ||
{ | ||
$alwaysProp = new AlwaysProp('An always value'); | ||
|
||
$this->assertSame('An always value', $alwaysProp()); | ||
} | ||
|
||
public function test_can_accept_callables(): void | ||
{ | ||
$callable = new class { | ||
public function __invoke() { | ||
return 'An always value'; | ||
} | ||
}; | ||
|
||
$alwaysProp = new AlwaysProp($callable); | ||
|
||
$this->assertSame('An always value', $alwaysProp()); | ||
} | ||
|
||
public function test_can_resolve_bindings_when_invoked(): void | ||
{ | ||
$alwaysProp = new AlwaysProp(function (Request $request) { | ||
return $request; | ||
}); | ||
|
||
$this->assertInstanceOf(Request::class, $alwaysProp()); | ||
} | ||
} |
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
Oops, something went wrong.