Skip to content

Commit 96c60a7

Browse files
authored
Merge pull request #244 from inertiajs/flush-shared
Add flushShared() method for clearing all shared data
2 parents 5ae5327 + de21e28 commit 96c60a7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/ResponseFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function getShared($key = null, $default = null)
4040
return $this->sharedProps;
4141
}
4242

43+
public function flushShared()
44+
{
45+
$this->sharedProps = [];
46+
}
47+
4348
public function version($version)
4449
{
4550
$this->version = $version;

tests/ResponseFactoryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ public function test_shared_data_can_be_shared_from_anywhere()
7171
]);
7272
}
7373

74+
public function test_can_flush_shared_data()
75+
{
76+
Inertia::share('foo', 'bar');
77+
$this->assertSame(['foo' => 'bar'], Inertia::getShared());
78+
Inertia::flushShared();
79+
$this->assertSame([], Inertia::getShared());
80+
}
81+
7482
public function test_can_create_lazy_prop()
7583
{
7684
$factory = new ResponseFactory();

0 commit comments

Comments
 (0)