Skip to content

Releases: bearsunday/BEAR.ReactJsModule

1.1.0

17 Jan 03:07
Compare
Choose a tag to compare

[Add] VoidV8Module #8

1.0.0

16 Jan 10:39
Compare
Choose a tag to compare

first stable release

0.3.3

20 Dec 08:07
Compare
Choose a tag to compare

Update airbnb eslint and hmr. See more at #6

Thanks @fiahfy !

0.3.2

19 Dec 07:42
Compare
Choose a tag to compare

update ui skeleton

0.3.1

16 Dec 10:06
Compare
Choose a tag to compare

Update package.json for lint and test #4

[BC Break] Update ReduxModule

15 Dec 08:26
Compare
Choose a tag to compare

Update ReduxModule and SsrInterface

BEAR.ReactJsModule

JavaScript code

You need three js bundled file.

  • react.bundle.js React library bundled code
  • {app-name}.bundle.js Application bundled code for client side
  • {ssr-app-name}.bundle.js Application bundled code for server side

You can include JavaScript client code (CSS, DOM ..) for {app}.bundle.js only. See more detail at the example.

Module Install

$distDir = dirname(__DIR__, 2) . '/var/www/dist';
$this->install(new ReduxModule($distDir, 'ssr_app');

In this canse, you need to place ssr-app.bundle.js at $baseDir directory.

ResourceOjbect

To inject SSR renderer, Annotate @Inject with @Named annotation to setRenderer setter method
with {ssr-app-name} application name.

use BEAR\Resource\RenderInterface;
use BEAR\Resource\ResourceObject;
use Ray\Di\Di\Inject;
use Ray\Di\Di\Named;

class Greeting extends ResourceObject
{
    /**
     * @Inject
     * @Named("ssr_app")
     */
    public function setRenderer(RenderInterface $renderer)
    {
        $this->renderer = $renderer;
    }

    public function onGet()
    {
        $this->body = [
            'title' => 'Greeting',
            'hello' => ['message' => 'konichiwa']
        ];

        return $this;
    }
}

Template

We need php template code. For exapmle, Index.php page resource needs Index.html.php template file.
You can get the value of body by escape() or raw().

<?php

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

return <<<"EOT"
<!doctype>
<html>
<head>
    <title>{$ssr->escape('title')}</title>
</head>
<body>
<div id="root">{$markup}</div>
<script src="build/react.bundle.js"></script>
<script src="build/app.bundle.js"></script>
<script>{$script}</script>
</body>
</html>
EOT;

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

0.2.0

25 Oct 10:12
Compare
Choose a tag to compare

[Add] ReduxModule #1

0.1.0

30 May 08:34
Compare
Choose a tag to compare

Initial release