From 8c3368b1592d4bbee98869db9d85f299b5df4798 Mon Sep 17 00:00:00 2001 From: Joseph Tibbertsma Date: Thu, 20 Oct 2016 20:39:19 -0700 Subject: [PATCH] Define new api registerRenderer The line doc/additional-reading/code-splitting.md should be changed to a url when/if this proposal gets accepted. This proposal was originally desribed here: https://github.com/shakacode/react_on_rails/issues/477 --- docs/api/javascript-api.md | 9 +++++++++ node_package/src/ReactOnRails.js | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/api/javascript-api.md b/docs/api/javascript-api.md index 49f608429..53cf30a27 100644 --- a/docs/api/javascript-api.md +++ b/docs/api/javascript-api.md @@ -57,4 +57,13 @@ The best source of docs is the main [ReactOnRails.js](../../node_package/src/Rea */ authenticityHeaders(otherHeaders = {}) + + /** + * Allows registration of renderers. A renderer is a function that accept three args: + * props, railsContext, and domNodeId, and is responsible for rendering a component + * to the DOM. Not available on the server. For one possible use case see: + * docs/additional-reading/code-splitting.md + * @param renderers (key is component name, value is renderer) + */ + registerRenderer(renderers) ``` diff --git a/node_package/src/ReactOnRails.js b/node_package/src/ReactOnRails.js index fa4c423b0..6a3808890 100644 --- a/node_package/src/ReactOnRails.js +++ b/node_package/src/ReactOnRails.js @@ -101,6 +101,17 @@ ctx.ReactOnRails = { return Authenticity.authenticityHeaders(otherHeaders); }, + /** + * Allows registration of renderers. A renderer is a function that accept three args: + * props, railsContext, and domNodeId, and is responsible for rendering a component + * to the DOM. Not available on the server. For one possible use case see: + * docs/additional-reading/code-splitting.md + * @param renderers (key is component name, value is renderer) + */ + registerRenderer(renderers) { + ComponentRegistry.registerRenderer(renderers); + }, + // ///////////////////////////////////////////////////////////////////////////// // INTERNALLY USED APIs // /////////////////////////////////////////////////////////////////////////////