From f6a13d354f216f6e4792c84eb9f0f07b3572bd82 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Mon, 16 Jul 2018 11:19:11 +0430 Subject: [PATCH 1/3] API for returning extra items returned by render server --- react/render_server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/react/render_server.py b/react/render_server.py index 2cecaa2..54f84c3 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -8,9 +8,10 @@ class RenderedComponent(object): - def __init__(self, markup, props): + def __init__(self, markup, props, extra): self.markup = markup self.props = props + self.extra = extra def __str__(self): return self.markup @@ -67,8 +68,9 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, obj = res.json() - markup = obj.get('markup', None) - err = obj.get('error', None) + markup = obj.pop('markup', None) + err = obj.pop('error', None) + extra = obj if err: if 'message' in err and 'stack' in err: @@ -80,7 +82,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, if markup is None: raise ReactRenderingError('Render server failed to return markup. Returned: {}'.format(obj)) - return RenderedComponent(markup, serialized_props) + return RenderedComponent(markup, serialized_props, extra) render_server = RenderServer() From db30691d18656d81907eb5daaedf0d0d306cbf6c Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Mon, 16 Jul 2018 20:44:21 +0430 Subject: [PATCH 2/3] Renamed extra to data --- react/render_server.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/react/render_server.py b/react/render_server.py index 54f84c3..13bbcae 100644 --- a/react/render_server.py +++ b/react/render_server.py @@ -8,10 +8,10 @@ class RenderedComponent(object): - def __init__(self, markup, props, extra): + def __init__(self, markup, props, data): self.markup = markup self.props = props - self.extra = extra + self.data = data def __str__(self): return self.markup @@ -70,7 +70,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, markup = obj.pop('markup', None) err = obj.pop('error', None) - extra = obj + data = obj if err: if 'message' in err and 'stack' in err: @@ -82,7 +82,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None, if markup is None: raise ReactRenderingError('Render server failed to return markup. Returned: {}'.format(obj)) - return RenderedComponent(markup, serialized_props, extra) + return RenderedComponent(markup, serialized_props, data) render_server = RenderServer() From 1167ba033ee1747005dd3dba1643d22c83e04233 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Mon, 16 Jul 2018 22:44:55 +0430 Subject: [PATCH 3/3] Added new data api to the docs --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index da12786..31470e9 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ The object returned has two properties: - `markup` - the rendered markup - `props` - the JSON-serialized props + - `data` - extra data returned by the render server If the object is coerced to a string, it will emit the value of the `markup` attribute. @@ -82,6 +83,8 @@ for a simple server that will cover most cases. The key files for the render ser - [render_server.js](examples/basic_rendering/render_server.js) - the server's source code - [package.json](examples/basic_rendering/package.json) - the server's dependencies, installable with [npm](http://npmjs.com) + +You can also return extra data from your render server and these data will be stored in `data` attribute of the response object. Using React on the front-end