Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Dev component scope #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion ReactJS.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class ReactJS {
* @var string
*/
$component,

/**
* The JavaScript scope in which React components are contained (defaults to global)
* @var string
*/
$componentScope,

/**
* Properties that go along with the component
Expand Down Expand Up @@ -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
Expand All @@ -99,6 +116,10 @@ function setErrorHandler($err) {
* @return string HTML string
*/
function getMarkup() {
if ($this->componentScope) {
$this->component = $this->componentScope.'.'.$this->component;
}

$js = sprintf(
"print(React.renderToString(React.createElement(%s, %s)))",
$this->component,
Expand Down Expand Up @@ -145,7 +166,7 @@ function getJS($where, $return_var = null) {
}

/**
* Executes Javascript using V8JS, with primitive exception handling
* Executes JavaScript using V8JS, with primitive exception handling
*
* @param string $js JS code to be executed
* @return string The execution response
Expand Down