Skip to content

Commit f94cf1e

Browse files
committed
Fix missing config to load phase on first page load
1 parent d20cf03 commit f94cf1e

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/VuexHydrateServiceProvider.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Illuminate\Database\Eloquent\Collection;
99
use Illuminate\Support\Facades\App;
1010
use Illuminate\Support\Facades\Blade;
11-
/* Macros */
11+
// Macros
1212
use Illuminate\Support\Facades\Response;
1313
use Illuminate\Support\Facades\Router;
1414
use Illuminate\Support\ServiceProvider;
@@ -38,6 +38,17 @@ public function register(): void
3838
*/
3939
public function boot()
4040
{
41+
if (!($this->app->configurationIsCached())) {
42+
$config = require __DIR__ . '/config.defaults.php';
43+
$this->app['config']->set('vuex-hydrate', array_merge_phase(
44+
$config,
45+
$this->app['config']->get('vuex-hydrate', [])
46+
));
47+
}
48+
49+
// php artisan vendor:publish --provider="Phased\Routing\PhaseServiceProvider" --tag="config"
50+
$this->publishes([__DIR__ . '/config.defaults.php' => config_path('vuex-hydrate.php')], 'config');
51+
4152
$this->autoDiscoverModuleLoaders();
4253

4354
$this->registerCommands();
@@ -52,9 +63,9 @@ public function boot()
5263
protected function autoDiscoverModuleLoaders()
5364
{
5465
// TODO: Register folders as namespaced modules
55-
$automatic = collect(glob(app_path().'/VuexLoaders/*ModuleLoader.php'))
66+
$automatic = collect(glob(app_path() . '/VuexLoaders/*ModuleLoader.php'))
5667
->map(function ($file) {
57-
$dropPath = Str::replaceFirst(app_path().'/', Container::getInstance()->getNamespace(), $file);
68+
$dropPath = Str::replaceFirst(app_path() . '/', Container::getInstance()->getNamespace(), $file);
5869
$dropExtension = Str::replaceLast('.php', '', $dropPath);
5970

6071
return str_replace('/', '\\', $dropExtension);
@@ -93,9 +104,9 @@ public function setDirectives()
93104
{
94105
Blade::directive('vuex', function () {
95106
return "<?='<script id=\'"
96-
.config('phase.initial_state_id', 'phase-state')."\'>window."
97-
.config('phase.initial_state_key', '__PHASE_STATE__')
98-
."='.Pderas\VuexHydrate\Facades\Vuex::toJson().'</script>';?>";
107+
. config('vuex-hydrate.initial_state_id', 'phase-state') . "\'>window."
108+
. config('vuex-hydrate.initial_state_key', '__PHASE_STATE__')
109+
. "='.Pderas\VuexHydrate\Facades\Vuex::toJson().'</script>';?>";
99110
});
100111
}
101112
}

src/config.defaults.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Determines whether to use the vuex state integration
7+
|--------------------------------------------------------------------------
8+
|
9+
| By default state management will be integrated if the Phased\State package
10+
| has been installed
11+
*/
12+
'state' => class_exists('\Pderas\VuexHydrate\Facades\Vuex'),
13+
14+
/*
15+
|--------------------------------------------------------------------------
16+
| Window key to save the initial state
17+
|--------------------------------------------------------------------------
18+
|
19+
| This is where the state will be stored on page load,
20+
| (If state integration is enabled of course)
21+
*/
22+
'initial_state_key' => '__PHASE_STATE__',
23+
24+
/*
25+
|--------------------------------------------------------------------------
26+
| <script id=initial_state_id />
27+
|--------------------------------------------------------------------------
28+
|
29+
| This is the id save to the state <script /> tag. Useful for removing the
30+
| <script> tag after load, or customizing in the event of name collisions
31+
*/
32+
'initial_state_id' => 'phase-state',
33+
];

0 commit comments

Comments
 (0)