Skip to content

Commit

Permalink
Merge pull request #8 from bearsunday/voidv8
Browse files Browse the repository at this point in the history
add VoidV8Module
  • Loading branch information
koriym authored Jan 17, 2017
2 parents 0730687 + a793c17 commit 16a7a3d
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,12 @@ EOT;

```


Note: `app.bundle.js` is client javascript code. The page is rendered fully even {$markup} is removed by client JS code.

### VoidV8Module

It is possible to install `VoidV8Module` to run non V8Js environment for clien side rendering only.

```php
$this->install(new FakeV8Module(new ReduxModule($distDir, 'ssr_hello')));
```
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "bear/reactjs-module",
"description": "Redux React Serevr-Side Rendering using V8Js module for BEAR.Sunday",
"require": {
"php": ">=7.0.0",
"bear/resource": "^1.2",
"koriym/redux-react-ssr": "^1.0.1"
"php": ">=7.1.0",
"bear/resource": "^1.4.0",
"koriym/redux-react-ssr": "^1.0.2"
},
"require-dev": {
"phpunit/phpunit": "^5.3"
Expand Down
26 changes: 26 additions & 0 deletions src/VoidV8Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the BEAR\ReactJsModule package
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace BEAR\ReactJsModule;

use Koriym\ReduxReactSsr\VoidV8Js;
use Ray\Di\AbstractModule;

class VoidV8Module extends AbstractModule
{
public function __construct($module = null)
{
parent::__construct($module);
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->bind(\V8Js::class)->to(VoidV8Js::class);
}
}
2 changes: 1 addition & 1 deletion tests/Fake/FakeReduxRo.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="stylesheet" href="/build/style.css">
</head>
<body>
<div id="root">{$view->markup}></div>
<div id="root">{$view->markup}</div>
<script src="build/react.bundle.js"></script>
<script src="build/app.bundle.js"></script>
<script>{$view->js}</script>
Expand Down
2 changes: 1 addition & 1 deletion tests/ReduxRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testRender()
<link rel="stylesheet" href="/build/style.css">
</head>
<body>
<div id="root"><div data-reactroot="" data-reactid="1" data-react-checksum="2096181691"><div data-reactid="2"><h1 data-reactid="3">konichiwa</h1><button data-reactid="4">Click</button></div></div>></div>
<div id="root"><div data-reactroot="" data-reactid="1" data-react-checksum="2096181691"><div data-reactid="2"><h1 data-reactid="3">konichiwa</h1><button data-reactid="4">Click</button></div></div></div>
<script src="build/react.bundle.js"></script>
<script src="build/app.bundle.js"></script>
<script>ReactDOM.render(React.createElement(Provider,{store:configureStore({"hello":{"message":"konichiwa"}})},React.createElement(App)),document.getElementById('root'));</script>
Expand Down
17 changes: 17 additions & 0 deletions tests/VoidV8ModuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace BEAR\ReactJsModule;

use Ray\Di\Injector;

class VoidV8ModuleTest extends \PHPUnit_Framework_TestCase
{
public function testModule()
{
$uiPath = __DIR__ . '/Fake';
$injector = new Injector(new VoidV8Module(new ReduxModule($uiPath, 'ssr_app')));
$ro = $injector->getInstance(FakeReduxRo::class);
$body = (string) $ro;
$this->assertContains('<div id="root"></div>', $body);
}
}

0 comments on commit 16a7a3d

Please sign in to comment.