Skip to content

Commit

Permalink
Merge pull request #7 from bearsunday/bcbreak
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
koriym authored Jan 16, 2017
2 parents 9854ead + f02a368 commit 0730687
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 174 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ You can get the value of body by `escape()` or `raw()`.
<?php

/* @var $ssr \BEAR\ReactJsModule\Ssr */
list($markup, $script) = $ssr->render(['hello']);
$view = $ssr->render(['hello']);

return <<<"EOT"
<!doctype>
Expand All @@ -112,10 +112,10 @@ return <<<"EOT"
<title>{$ssr->escape('title')}</title>
</head>
<body>
<div id="root">{$markup}</div>
<div id="root">{$view->markup}</div>
<script src="build/react.bundle.js"></script>
<script src="build/app.bundle.js"></script>
<script>{$script}</script>
<script>{$view->js}</script>
</body>
</html>
EOT;
Expand Down
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"require": {
"php": ">=7.0.0",
"bear/resource": "^1.2",
"koriym/redux-react-ssr": "^0.2"
"koriym/redux-react-ssr": "^1.0.1"
},
"require-dev": {
"phpunit/phpunit": "^5.3"
Expand All @@ -18,10 +18,7 @@
],
"autoload": {
"psr-4": {
"BEAR\\ReactJsModule\\": [
"src/",
"src-deprecated"
]
"BEAR\\ReactJsModule\\": "src/"
}
},
"autoload-dev": {
Expand Down
6 changes: 3 additions & 3 deletions docs/demo/Greeting.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use BEAR\ReactJsModule\Ssr;

/* @var $ssr Ssr */
list($markup, $script) = $ssr->render(['hello']);
$view = $ssr->render(['hello']);

return <<<"EOT"
<!doctype>
Expand All @@ -12,10 +12,10 @@
<title>{$ssr->escape('title')}</title>
</head>
<body>
<div id="root">{$markup}</div>
<div id="root">{$view->markup}</div>
<script src="build/react.bundle.js"></script>
<script src="build/app.bundle.js"></script>
<script>{$script}</script>
<script>{$view->js}</script>
</body>
</html>
EOT;
51 changes: 0 additions & 51 deletions src-deprecated/ReactJsModule.php

This file was deleted.

44 changes: 0 additions & 44 deletions src-deprecated/ReduxServerSideRenderer.php

This file was deleted.

35 changes: 0 additions & 35 deletions src-deprecated/ReduxSsr.php

This file was deleted.

8 changes: 8 additions & 0 deletions src/ReduxModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace BEAR\ReactJsModule;

use BEAR\Resource\RenderInterface;
use Koriym\ReduxReactSsr\ExceptionHandler;
use Koriym\ReduxReactSsr\ExceptionHandlerInterface;
use Koriym\ReduxReactSsr\ReduxReactJs;
use Koriym\ReduxReactSsr\ReduxReactJsInterface;
use Ray\Di\AbstractModule;
Expand Down Expand Up @@ -53,5 +55,11 @@ protected function configure()
$this->bind(ReduxReactJsInterface::class)->annotatedWith($this->name)->toConstructor(ReduxReactJs::class, $reduxReactJsname);
$reduxRendererName = "appName=redux_app_name_{$this->name},redux={$this->name}";
$this->bind(RenderInterface::class)->annotatedWith($this->name)->toConstructor(ReduxRenderer::class, $reduxRendererName);
$this->bind(ExceptionHandlerInterface::class)->to(ExceptionHandler::class);
$this->bind(\V8Js::class)->toConstructor(\V8Js::class, 'object_name=v8js_object_name,variables=v8js_variables,extensions=v8js_extensions,snapshot_blob=v8js_snapshot_blob');
$this->bind()->annotatedWith('v8js_object_name')->toInstance('');
$this->bind()->annotatedWith('v8js_variables')->toInstance([]);
$this->bind()->annotatedWith('v8js_extensions')->toInstance([]);
$this->bind()->annotatedWith('v8js_snapshot_blob')->toInstance('');
}
}
7 changes: 4 additions & 3 deletions src/Ssr.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use BEAR\ReactJsModule\Exception\BodyKeyNotExistsException;
use BEAR\Resource\ResourceObject;
use Koriym\ReduxReactSsr\ReduxReactJs;
use Koriym\ReduxReactSsr\View;

final class Ssr implements SsrInterface
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public function __construct(ResourceObject $ro, ReduxReactJs $reduxReactJs, stri
/**
* {@inheritdoc}
*/
public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : array
public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : View
{
$body = $this->ro->body;
$store = [];
Expand All @@ -59,9 +60,9 @@ public function render(array $storeNames, string $rootContainer = 'App', string
}
$store[$storeName] = $body[$storeName];
}
list($markup, $script) = $this->reduxReactJs->__invoke($rootContainer, $store, $domId);
$view = $this->reduxReactJs->__invoke($rootContainer, $store, $domId);

return [$markup, $script];
return $view;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/SsrInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
namespace BEAR\ReactJsModule;

use Koriym\ReduxReactSsr\View;

interface SsrInterface
{
/**
Expand All @@ -19,7 +21,7 @@ interface SsrInterface
*
* @return array [$markup, $script]
*/
public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : array;
public function render(array $storeNames, string $rootContainer = 'App', string $domId = 'root') : View;

/**
* Get escaped resource body item
Expand Down
6 changes: 3 additions & 3 deletions tests/Fake/FakeReduxRo.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Koriym\ReduxReactSsr\ReduxSsrInterface;

/* @var $ssr Ssr */
list($markup, $script) = $ssr->render(['hello']);
$view = $ssr->render(['hello']);

return <<<"EOD"
<!doctype>
Expand All @@ -16,10 +16,10 @@
<link rel="stylesheet" href="/build/style.css">
</head>
<body>
<div id="root">{$markup}></div>
<div id="root">{$view->markup}></div>
<script src="build/react.bundle.js"></script>
<script src="build/app.bundle.js"></script>
<script>{$script}</script>
<script>{$view->js}</script>
</body>
</html>
EOD;
21 changes: 0 additions & 21 deletions tests/ReactJsModuleTest.php

This file was deleted.

6 changes: 5 additions & 1 deletion tests/ReduxModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ public function testModule()
{
$uiPath = __DIR__ . '/Fake';
$injector = new Injector(new ReduxModule($uiPath, 'ssr_app'));
$ro = $injector->getInstance(FakeReduxRo::class);
try {
$ro = $injector->getInstance(FakeReduxRo::class);
} catch (\Exception $e) {
echo $e;
}
$this->assertInstanceOf(ReduxRenderer::class, $ro->renderer);
}
}
16 changes: 13 additions & 3 deletions tests/ReduxRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BEAR\ReactJsModule;

use BEAR\ReactJsModule\Exception\BodyKeyNotExistsException;
use Koriym\ReduxReactSsr\ExceptionHandler;
use Koriym\ReduxReactSsr\ReduxReactJs;

class ReduxRendererTest extends \PHPUnit_Framework_TestCase
Expand All @@ -13,7 +14,12 @@ public function testRender()
$appBundleJs = file_get_contents(__DIR__ . '/Fake/app.bundle.js');
$reduxRenderer = new ReduxRenderer(
'app',
new ReduxReactJs($reactBundleJs, $appBundleJs)
new ReduxReactJs(
$reactBundleJs,
$appBundleJs,
new ExceptionHandler(),
new \V8Js()
)
);
$ro = new FakeReduxRo;
$ro->setRenderer($reduxRenderer);
Expand All @@ -31,7 +37,7 @@ public function testRender()
<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>
<script>ReactDOM.render(React.createElement(Provider,{store:configureStore({"hello":{"message":"konichiwa"}})},React.createElement(App)),document.getElementById('root'));</script>
</body>
</html>
EOT;
Expand All @@ -45,7 +51,11 @@ public function testRenderWithNoKey()
$appBundleJs = file_get_contents(__DIR__ . '/Fake/app.bundle.js');
$reduxRenderer = new ReduxRenderer(
'app',
new ReduxReactJs($reactBundleJs, $appBundleJs)
new ReduxReactJs(
$reactBundleJs,
$appBundleJs,
new ExceptionHandler(),
new \V8Js())
);
$ro = new FakeReduxRo;
unset($ro->body['hello']);
Expand Down
5 changes: 4 additions & 1 deletion tests/SsrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BEAR\ReactJsModule;

use BEAR\ReactJsModule\Exception\BodyKeyNotExistsException;
use Koriym\ReduxReactSsr\ExceptionHandler;
use Koriym\ReduxReactSsr\ReduxReactJs;

class SsrTest extends \PHPUnit_Framework_TestCase
Expand All @@ -18,7 +19,9 @@ public function setUp()
new FakeReduxRo,
new ReduxReactJs(
file_get_contents(__DIR__ . '/Fake/react.bundle.js'),
file_get_contents(__DIR__ . '/Fake/app.bundle.js')
file_get_contents(__DIR__ . '/Fake/app.bundle.js'),
new ExceptionHandler(),
new \V8Js()
),
'app'
);
Expand Down

0 comments on commit 0730687

Please sign in to comment.