Skip to content

Commit 0bf6c4c

Browse files
committed
Merge pull request #24 from talyssonoc/config_changes
Config changes
2 parents 39ed584 + 5c0a852 commit 0bf6c4c

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 0.9 (2015-05-27)
2+
3+
Features:
4+
5+
- The `ReactServiceProvider` is now deferred.
6+
- Configs now are on a separated file from `config/app.php`, it's `config/react.php` now.
7+
8+
# 0.8 (2015-05-09)
9+
10+
Features:
11+
12+
- React and component's source are now cached at production.

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can see how to install it here: [how to install v8js](install_v8js.md).
1717
You just need to add this to your `composer.json`'s `"require"`:
1818

1919
```json
20-
"talyssonoc/react-laravel": "0.8"
20+
"talyssonoc/react-laravel": "0.9"
2121
```
2222

2323
Also you got to set the `minimum-stability` of your `composer.json` to `dev`, adding this:
@@ -34,6 +34,14 @@ Then run:
3434

3535
After that you should add `'React\ReactServiceProvider'` to your providers at the `config/app.php` file of your Laravel app.
3636

37+
And then run:
38+
39+
```sh
40+
php artisan vendor:publish
41+
```
42+
43+
And the `react.php` file will be available at the `config` folder of your app.
44+
3745
# Usage
3846

3947
After the installation and configuration, you'll be able to use the `@react_component` directive in your views.
@@ -76,13 +84,13 @@ You can choose to use any React installation greater than `v0.13.1`, but if you'
7684

7785
# Configurations
7886

79-
You can add settings to `react-laravel` adding this to your `config/app.php` file:
87+
You can change settings to `react-laravel` at the `config/react.php` file:
8088

8189
```php
82-
'react' => [
90+
return [
8391
'source' => 'path_for_react.js',
8492
'components' => 'path_for_file_containing_your_components.js'
85-
]
93+
];
8694
```
8795

8896
Both of then are optional.

config/config.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
'source' => public_path('vendor/react-laravel/react.js'),
5+
'components' => public_path('js/components.js'),
6+
];

lib/ReactServiceProvider.php

+17-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
class ReactServiceProvider extends ServiceProvider {
1010

11+
protected $defer = true;
12+
1113
public function boot() {
1214

1315
Blade::extend(function($view, $compiler) {
@@ -17,8 +19,12 @@ public function boot() {
1719
});
1820

1921
$this->publishes([
20-
__DIR__ . '/../assets' => public_path('vendor/react-laravel'),
21-
]);
22+
__DIR__ . '/../assets' => public_path('vendor/react-laravel'),
23+
], 'assets');
24+
25+
$this->publishes([
26+
__DIR__ . '/../config/config.php' => config_path('react.php'),
27+
], 'config');
2228
}
2329

2430
public function register() {
@@ -34,26 +40,25 @@ public function register() {
3440

3541
}
3642
else {
37-
$defaultReactPath = implode(DIRECTORY_SEPARATOR,
38-
[App::publicPath(), 'vendor', 'react-laravel', 'react.js']);
3943

40-
$defaultComponentsPath = implode(DIRECTORY_SEPARATOR,
41-
[App::publicPath(), 'js', 'components.js']);
44+
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'react');
4245

43-
$reactPath = Config::get('app.react.source', $defaultReactPath);
44-
$componentsPath = Config::get('app.react.components', $defaultComponentsPath);
45-
46-
$reactSource = file_get_contents($reactPath);
47-
$componentsSource = file_get_contents($componentsPath);
46+
$reactSource = file_get_contents(config('react.source'));
47+
$componentsSource = file_get_contents(config('react.components'));
4848

4949
if(App::environment('production')) {
5050
Cache::forever('reactSource', $reactSource);
5151
Cache::forever('componentsSource', $componentsSource);
5252
}
53-
5453
}
5554

5655
return new React($reactSource, $componentsSource);
5756
});
5857
}
58+
59+
public function provides() {
60+
return ['React'];
61+
}
62+
63+
5964
}

0 commit comments

Comments
 (0)