From 0f89061c80c9e81e228bd6cd831e39a867a9c262 Mon Sep 17 00:00:00 2001 From: Jack Chapple Date: Thu, 28 May 2015 14:43:48 +0100 Subject: [PATCH] Added interface to allow for setting the Javascript scope in which React components are contained --- ReactJS.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ReactJS.php b/ReactJS.php index 89d961e..e6d8c15 100644 --- a/ReactJS.php +++ b/ReactJS.php @@ -21,6 +21,12 @@ class ReactJS { * @var string */ $component, + + /** + * The Javascript scope in which React components are contained (defaults to global) + * @var string + */ + $componentScope = 'global', /** * Properties that go along with the component @@ -80,6 +86,17 @@ function setComponent($component, $data = null) { $this->data = json_encode($data); return $this; } + + /** + * Sets the Javascript scope in which React components are contained + * + * @param string $scope The Javascript scope + * @return ReactJS $this instance + */ + function setComponentScope($scope) { + $this->componentScope = $scope; + return $this; + } /** * Custom error handler. The default one var_dumps the exception @@ -100,7 +117,8 @@ function setErrorHandler($err) { */ function getMarkup() { $js = sprintf( - "print(React.renderToString(React.createElement(%s, %s)))", + "print(React.renderToString(React.createElement(%s.%s, %s)))", + $this->componentScope, $this->component, $this->data);