From d2a7b0d25745dae251dc7e49b1c00d1d1f85dce7 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 16 Jan 2017 19:05:38 +0900 Subject: [PATCH 1/2] fix markup prop --- src/ReduxReactJs.php | 8 ++++---- tests/ReduxReactJsTest.php | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ReduxReactJs.php b/src/ReduxReactJs.php index 0fd5237..9a16e01 100644 --- a/src/ReduxReactJs.php +++ b/src/ReduxReactJs.php @@ -53,10 +53,10 @@ public function __invoke(string $rootContainer, array $store, string $id) : View $view = new View; try { $v8 = $this->v8->executeString($code); - $view->html = $v8->html; + $view->markup = $v8->markup; } catch (\V8JsScriptException $e) { $this->handler->__invoke($e); - $view->html = ''; + $view->markup = ''; } $view->js = "ReactDOM.render(React.createElement(Provider,{store:configureStore($storeJson)},React.createElement(App)),document.getElementById('{$id}'));"; @@ -73,8 +73,8 @@ private function getServerSideRenderingCode(string $rootContainer, string $store var React = global.React, ReactDOM = global.ReactDOM, ReactDOMServer = global.ReactDOMServer; {$this->appBundleSrc} var Provider = global.Provider, configureStore = global.configureStore, App = global.{$rootContainer}; -var html = ReactDOMServer.renderToString(React.createElement(Provider, { store: configureStore({$storeJson}) }, React.createElement(App))); -tmp = {html: html}; +var markup = ReactDOMServer.renderToString(React.createElement(Provider, { store: configureStore({$storeJson}) }, React.createElement(App))); +tmp = {markup: markup}; EOT; return $code; diff --git a/tests/ReduxReactJsTest.php b/tests/ReduxReactJsTest.php index 32f9a62..4d754c4 100644 --- a/tests/ReduxReactJsTest.php +++ b/tests/ReduxReactJsTest.php @@ -24,8 +24,8 @@ public function testInvoke() { $state = ['hello' => ['message' => 'Hello SSR !']]; $view = $this->ssr->__invoke('App', $state, 'root'); - $this->assertStringStartsWith('
Hello SSR !', $view->html); + $this->assertStringStartsWith('
Hello SSR !', $view->markup); $this->assertSame('ReactDOM.render(React.createElement(Provider,{store:configureStore({"hello":{"message":"Hello SSR !"}})},React.createElement(App)),document.getElementById(\'root\'));', $view->js); } @@ -47,6 +47,6 @@ public function testInvalidValue() { $state = ['hello' => ['__INVALID__' => 'Hello SSR !']]; $view = @$this->ssr->__invoke('_INVALID_', $state, 'root'); - $this->assertSame('', $view->html); + $this->assertSame('', $view->markup); } } From 11dae3456280a8150ba3224554a71dd6315ecf9c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 16 Jan 2017 19:25:13 +0900 Subject: [PATCH 2/2] fix type --- src/ReduxReactJs.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ReduxReactJs.php b/src/ReduxReactJs.php index 9a16e01..7feeaf6 100644 --- a/src/ReduxReactJs.php +++ b/src/ReduxReactJs.php @@ -31,11 +31,20 @@ final class ReduxReactJs implements ReduxReactJsInterface private $v8; /** - * @param string $reactBundleSrc Bundled code include React, ReactDom, and Redux - * @param string $appBundleSrc Bundled application code - * @param ExceptionHandler $handler V8Js exception handler + * @param string $reactBundleSrc + * @param string $appBundleSrc + * @param ExceptionHandlerInterface $handler */ - public function __construct(string $reactBundleSrc, string $appBundleSrc, ExceptionHandler $handler, V8Js $v8Js) + + /** + * ReduxReactJs constructor. + * + * @param string $reactBundleSrc Bundled code include React, ReactDom, and Redux + * @param string $appBundleSrc Bundled application code + * @param ExceptionHandlerInterface $handler + * @param V8Js $v8Js V8Js exception handler + */ + public function __construct(string $reactBundleSrc, string $appBundleSrc, ExceptionHandlerInterface $handler, V8Js $v8Js) { $this->reactBundleSrc = $reactBundleSrc; $this->appBundleSrc = $appBundleSrc;