API¶
React Module¶
-
class
react.React(opts)[source]¶ Wrap basic functionality to render react views. The only thing it cares is that there is a global.RenderToString(opts) function defined in the pre-loaded js libs. This render function renders a component, matches a route, etc and returns the rendered view or a json with extra data.
Parameters: opts (dict) – Dict of parameters the js render function will receive, it must be serializable with json -
as_json()[source]¶ Serialize
optsinto a json. This is used internally and can be overridden to provide a faster json serializer.Returns: Opts in json format Return type: str
-
render()[source]¶ Returns: Result of the JS render call Return type: str Raises: react.excepts.V8Error – if there was an error running the JS script
-
-
react.set_up()[source]¶ Setup V8 machinery and define some basic variables into the global V8 context. Should be called once in the app lifetime.
Raises: react.excepts.V8Error – if there was an error running the JS script. This should usually not be handled
Utils Module¶
-
react.utils.set_up()[source]¶ Setup V8 machinery. Should be called once in the app lifetime, usually through
react.set_up().Raises: react.excepts.V8Error – if there was an error. This should usually not be handled
-
react.utils.load_libs(scripts_paths)[source]¶ Load JavaScript libs into the global V8 context for later use.
Parameters: scripts_paths (list) – List of javascript files Raises: react.excepts.V8Error – if there was an error running the JS script
-
react.utils.run_script(script)[source]¶ Execute a script (i.e. a function call) into the global V8 context.
Parameters: script (str) – Code to execute within the V8 context Raises: react.excepts.V8Error – if there was an error running the JS script