2017 © Pedro Peláez
 

library ssr-module

Javascript SSR module for BEAR.Sunday

image

bear/ssr-module

Javascript SSR module for BEAR.Sunday

  • Thursday, October 12, 2017
  • by koriym
  • Repository
  • 1 Watchers
  • 1 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

BEAR.SsrModule

Scrutinizer Code Quality Code Coverage Build Status, (*1)

JavaScript server side rendering (SSR) module interface for BEAR.Sunday, (*2)

Prerequisites

  • php7.1
  • V8Js (Optional)

Install

Composer Install

composer require bear/ssr-module

Module Install

$buildDir = dirname(__DIR__, 2) . '/var/www/build';
$this->install(new SsrModule($buildDir, 'index_ssr');

In this canse, you need to place index_ssr.bundle.js file at $baseDir directory. This JS is used server side rendring (SSR) only., (*3)

@Ssr Annotation

Basic

/**
 * @Ssr(app="index_ssr")
 */
public function onGet()
{ 
    $this->body = [
        'name' => 'World'
    ];

    return $this;
}

Annotate @Ssr at the method where you want to SSR. Set JS application name to app., (*4)

JS Render Application

Here is a very minimalistic JS application. Export render function to render. Use koriym/js-ui-skeletom to create Javascript UI application., (*5)

const render = state => (
  `Hello ${state.name}`
)

State and metas

In SSR application, you sometime want to deal two kind of data. One is for client side which means you are OK to be a public in HTML. One is server side only., (*6)

You can separate state and meta data by custom attribute in @Ssr annotation. metas are only used in server side., (*7)

/**
 * @Ssr(
 *   app="index_ssr",
 *   state={"name", "age"},
 *   meta={"title"}
 * )
 */
public function onGet()
{ 
    $this->body = [
        'name' => 'World',
        'age' => 4.6E8;
        'title' => 'Age of the World'
    ];

    return $this;
}

render.js, (*8)

const render = (preloadedState, metas) => {
  return
  `<html>
    <head>
      <title>${escape(metas.title)}</title>
    </head>
    <body>
      <script>window.__PRELOADED_STATE__ = ${serialize(preloadedState)}</script>
    <body>
  </html>`
};
export default render;

```, (*9)

The Versions

12/10 2017

1.x-dev

1.9999999.9999999.9999999-dev

Javascript SSR module for BEAR.Sunday

  Sources   Download

MIT

The Requires

 

The Development Requires

javascript react v8 ssr

12/10 2017

1.0.1

1.0.1.0

Javascript SSR module for BEAR.Sunday

  Sources   Download

MIT

The Requires

 

The Development Requires

javascript react v8 ssr

12/10 2017

dev-hotfix_v8_report_uncaught_exceptions

dev-hotfix_v8_report_uncaught_exceptions

Javascript SSR module for BEAR.Sunday

  Sources   Download

MIT

The Requires

 

The Development Requires

javascript react v8 ssr

11/05 2017

1.0.0

1.0.0.0

Javascript SSR module for BEAR.Sunday

  Sources   Download

MIT

The Requires

 

The Development Requires

javascript react v8 ssr