new PageRenderer()
Methods
-
clearState()
-
Clears the state to the currently rendered view.
This method has no effect at the server-side.
-
mount(controller, view, pageResources, routeOptions)
-
Renders the page using the provided controller and view. The actual behavior of this method differs at the client-side and the at server-side in the following way:
At the server, the method first waits for all the resources to load, and then renders the page to a string containing HTML markup to send to the client.
At the client, the method uses the already available resources to render the page into DOM, re-using the DOM created from the HTML markup send by the server if possible. After this the method will re-render the page every time another resource being loaded finishes its loading and becomes available.
Note that the method renders the page at the client-side only after all resources have been loaded if this is the first time this method is invoked at the client.
Parameters:
Name Type Description controller
Controller The current page controller.
view
React.Component The page's view.
pageResources
Object.<string, (*|Promise.<*>)> The resources for the view loaded by the controller.
routeOptions
Object The current route options.
Returns:
A promise that will resolve to information about the rendered page. The
status
will contain the HTTP status code to send to the client (at the server side) or determine the type of error page to navigate to (at the client side). Thecontent
field will contain the rendered markup of the page at the server-side, ornull
at the client-side.- Type
- Promise.<{status: number, content: ?string, pageState: Object.<string, ?>}>
-
setState( [state])
-
Sets the provided state to the currently rendered view.
This method has no effect at the server-side.
Parameters:
Name Type Argument Default Description state
Object.<string, *> <optional>
{} The state to set to the currently rendered view.
-
unmount()
-
Unmounts the view from the DOM.
This method has no effect at the server-side.
-
update(controller, resourcesUpdate)
-
Handles update of the current route that does not replace the current controller and view.
The method will use the already available resource to update the controller's state and the view immediately. After that, the method will update the controller's state and view with every resource that becomes resolved.
Parameters:
Name Type Description controller
Controller The current page controller.
resourcesUpdate
Object.<string, (*|Promise.<*>)> The resources that represent the update the of current state according to the current route and its parameters.
Returns:
A promise that will resolve to information about the rendered page. The
status
will contain the HTTP status code to send to the client (at the server side) or determine the type of error page to navigate to (at the client side). Thecontent
field will contain the rendered markup of the page at the server-side, ornull
at the client-side.- Type
- Promise.<{status: number, content: ?string, pageState: Object.<string, *>}>