Skip to content

Commit

Permalink
added component return instead of element return
Browse files Browse the repository at this point in the history
  • Loading branch information
yawetse committed Jan 19, 2018
1 parent 2c05353 commit df57d1e
Show file tree
Hide file tree
Showing 14 changed files with 409 additions and 48 deletions.
42 changes: 34 additions & 8 deletions dist/rjx.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ function getFunctionFromEval() {

/**
* Returns a new React Component
* @param {Object} options
* @param {Object} [options.reactComponent={}] - an object of functions used for create-react-class
* @param {Object} options.reactComponent.render.body - Valid RJX JSON
* @param {String} options.reactComponent.getDefaultProps.body - return an object for the default props
* @param {String} options.reactComponent.getInitialState.body - return an object for the default state
* @param {Object} [returnFactory=true] - returns a React component if true otherwise returns Component Class
* @param {Object} [reactComponent={}] - an object of functions used for create-react-class
* @param {Object} reactComponent.render.body - Valid RJX JSON
* @param {String} reactComponent.getDefaultProps.body - return an object for the default props
* @param {String} reactComponent.getInitialState.body - return an object for the default state
* @returns {Function}
* @see {@link https://reactjs.org/docs/react-without-es6.html}
*/
Expand Down Expand Up @@ -811,6 +811,30 @@ function getComponentProps() {
}, {});
}

/**
* Resolves rjx.__dangerouslyInsertReactComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.
* @param {Object} options
* @param {Object} options.rjx - Valid RJX JSON
// * @param {Object} [options.resources={}] - object to use for asyncprops, usually a result of an asynchronous call
* @returns {Object} resolved object of React Components
*/
function getReactComponentProps() {
var _this3 = this;

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var rjx = options.rjx;

return Object.keys(rjx.__dangerouslyInsertReactComponents).reduce(function (cprops, cpropName) {
// eslint-disable-next-line
cprops[cpropName] = getComponentFromMap$1({
rjx: { component: rjx.__dangerouslyInsertReactComponents[cpropName] },
reactComponents: _this3.reactComponents,
componentLibraries: _this3.componentLibraries
});
return cprops;
}, {});
}

/**
* Takes a function string and returns a function on either this.props or window. The function can only be 2 levels deep
* @param {Object} options
Expand Down Expand Up @@ -904,7 +928,7 @@ function getFunctionProps() {
* @returns {Object} resolved object of with React Components from a window property window.__rjx_custom_elements
*/
function getWindowComponents() {
var _this3 = this;
var _this4 = this;

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var allProps = options.allProps,
Expand All @@ -918,7 +942,7 @@ function getWindowComponents() {
var windowKEY = typeof windowComponents[key] === 'string' ? windowComponents[key].replace(windowFuncPrefix + '.', '') : '';
if (typeof windowComponents[key] === 'string' && windowComponents[key].indexOf(windowFuncPrefix) !== -1 && typeof window.__rjx_custom_elements[windowKEY] === 'function') {
var windowComponentElement = window.__rjx_custom_elements[windowKEY];
var windowComponentProps = allProps['__windowComponentProps'] ? allProps['__windowComponentProps'] : _this3.props;
var windowComponentProps = allProps['__windowComponentProps'] ? allProps['__windowComponentProps'] : _this4.props;
allProps[key] = React.createElement(windowComponentElement, windowComponentProps, null);
}
});
Expand Down Expand Up @@ -1009,7 +1033,8 @@ function getComputedProps$1() {
//allowing javascript injections
var evalProps = rjx.__dangerouslyEvalProps || rjx.__dangerouslyBindEvalProps ? getEvalProps.call(this, { rjx: rjx }) : {};
var insertedComponents = rjx.__dangerouslyInsertComponents ? getComponentProps.call(this, { rjx: rjx, resources: resources, debug: debug }) : {};
var allProps = Object.assign({ key: renderIndex$$1 }, thisprops, rjx.props, asyncprops, windowprops, evalProps, insertedComponents);
var insertedReactComponents = rjx.__dangerouslyInsertReactComponents ? getReactComponentProps.call(this, { rjx: rjx, debug: debug }) : {};
var allProps = Object.assign({ key: renderIndex$$1 }, thisprops, rjx.props, asyncprops, windowprops, evalProps, insertedComponents, insertedReactComponents);
var computedProps = Object.assign({}, allProps, rjx.__functionProps ? getFunctionProps.call(this, { allProps: allProps, rjx: rjx }) : {}, rjx.__windowComponents ? getWindowComponents.call(this, { allProps: allProps, rjx: rjx }) : {});

return computedProps;
Expand All @@ -1025,6 +1050,7 @@ var rjxProps = Object.freeze({
getRJXProps: getRJXProps,
getEvalProps: getEvalProps,
getComponentProps: getComponentProps,
getReactComponentProps: getReactComponentProps,
getFunctionFromProps: getFunctionFromProps,
getFunctionProps: getFunctionProps,
getWindowComponents: getWindowComponents,
Expand Down
42 changes: 34 additions & 8 deletions dist/rjx.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ function getFunctionFromEval() {

/**
* Returns a new React Component
* @param {Object} options
* @param {Object} [options.reactComponent={}] - an object of functions used for create-react-class
* @param {Object} options.reactComponent.render.body - Valid RJX JSON
* @param {String} options.reactComponent.getDefaultProps.body - return an object for the default props
* @param {String} options.reactComponent.getInitialState.body - return an object for the default state
* @param {Object} [returnFactory=true] - returns a React component if true otherwise returns Component Class
* @param {Object} [reactComponent={}] - an object of functions used for create-react-class
* @param {Object} reactComponent.render.body - Valid RJX JSON
* @param {String} reactComponent.getDefaultProps.body - return an object for the default props
* @param {String} reactComponent.getInitialState.body - return an object for the default state
* @returns {Function}
* @see {@link https://reactjs.org/docs/react-without-es6.html}
*/
Expand Down Expand Up @@ -805,6 +805,30 @@ function getComponentProps() {
}, {});
}

/**
* Resolves rjx.__dangerouslyInsertReactComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.
* @param {Object} options
* @param {Object} options.rjx - Valid RJX JSON
// * @param {Object} [options.resources={}] - object to use for asyncprops, usually a result of an asynchronous call
* @returns {Object} resolved object of React Components
*/
function getReactComponentProps() {
var _this3 = this;

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var rjx = options.rjx;

return Object.keys(rjx.__dangerouslyInsertReactComponents).reduce(function (cprops, cpropName) {
// eslint-disable-next-line
cprops[cpropName] = getComponentFromMap$1({
rjx: { component: rjx.__dangerouslyInsertReactComponents[cpropName] },
reactComponents: _this3.reactComponents,
componentLibraries: _this3.componentLibraries
});
return cprops;
}, {});
}

/**
* Takes a function string and returns a function on either this.props or window. The function can only be 2 levels deep
* @param {Object} options
Expand Down Expand Up @@ -898,7 +922,7 @@ function getFunctionProps() {
* @returns {Object} resolved object of with React Components from a window property window.__rjx_custom_elements
*/
function getWindowComponents() {
var _this3 = this;
var _this4 = this;

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var allProps = options.allProps,
Expand All @@ -912,7 +936,7 @@ function getWindowComponents() {
var windowKEY = typeof windowComponents[key] === 'string' ? windowComponents[key].replace(windowFuncPrefix + '.', '') : '';
if (typeof windowComponents[key] === 'string' && windowComponents[key].indexOf(windowFuncPrefix) !== -1 && typeof window.__rjx_custom_elements[windowKEY] === 'function') {
var windowComponentElement = window.__rjx_custom_elements[windowKEY];
var windowComponentProps = allProps['__windowComponentProps'] ? allProps['__windowComponentProps'] : _this3.props;
var windowComponentProps = allProps['__windowComponentProps'] ? allProps['__windowComponentProps'] : _this4.props;
allProps[key] = React.createElement(windowComponentElement, windowComponentProps, null);
}
});
Expand Down Expand Up @@ -1003,7 +1027,8 @@ function getComputedProps$1() {
//allowing javascript injections
var evalProps = rjx.__dangerouslyEvalProps || rjx.__dangerouslyBindEvalProps ? getEvalProps.call(this, { rjx: rjx }) : {};
var insertedComponents = rjx.__dangerouslyInsertComponents ? getComponentProps.call(this, { rjx: rjx, resources: resources, debug: debug }) : {};
var allProps = Object.assign({ key: renderIndex$$1 }, thisprops, rjx.props, asyncprops, windowprops, evalProps, insertedComponents);
var insertedReactComponents = rjx.__dangerouslyInsertReactComponents ? getReactComponentProps.call(this, { rjx: rjx, debug: debug }) : {};
var allProps = Object.assign({ key: renderIndex$$1 }, thisprops, rjx.props, asyncprops, windowprops, evalProps, insertedComponents, insertedReactComponents);
var computedProps = Object.assign({}, allProps, rjx.__functionProps ? getFunctionProps.call(this, { allProps: allProps, rjx: rjx }) : {}, rjx.__windowComponents ? getWindowComponents.call(this, { allProps: allProps, rjx: rjx }) : {});

return computedProps;
Expand All @@ -1019,6 +1044,7 @@ var rjxProps = Object.freeze({
getRJXProps: getRJXProps,
getEvalProps: getEvalProps,
getComponentProps: getComponentProps,
getReactComponentProps: getReactComponentProps,
getFunctionFromProps: getFunctionFromProps,
getFunctionProps: getFunctionProps,
getWindowComponents: getWindowComponents,
Expand Down
42 changes: 34 additions & 8 deletions dist/rjx.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -28341,11 +28341,11 @@ function getFunctionFromEval() {

/**
* Returns a new React Component
* @param {Object} options
* @param {Object} [options.reactComponent={}] - an object of functions used for create-react-class
* @param {Object} options.reactComponent.render.body - Valid RJX JSON
* @param {String} options.reactComponent.getDefaultProps.body - return an object for the default props
* @param {String} options.reactComponent.getInitialState.body - return an object for the default state
* @param {Object} [returnFactory=true] - returns a React component if true otherwise returns Component Class
* @param {Object} [reactComponent={}] - an object of functions used for create-react-class
* @param {Object} reactComponent.render.body - Valid RJX JSON
* @param {String} reactComponent.getDefaultProps.body - return an object for the default props
* @param {String} reactComponent.getInitialState.body - return an object for the default state
* @returns {Function}
* @see {@link https://reactjs.org/docs/react-without-es6.html}
*/
Expand Down Expand Up @@ -28564,6 +28564,30 @@ function getComponentProps() {
}, {});
}

/**
* Resolves rjx.__dangerouslyInsertReactComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.
* @param {Object} options
* @param {Object} options.rjx - Valid RJX JSON
// * @param {Object} [options.resources={}] - object to use for asyncprops, usually a result of an asynchronous call
* @returns {Object} resolved object of React Components
*/
function getReactComponentProps() {
var _this3 = this;

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var rjx = options.rjx;

return Object.keys(rjx.__dangerouslyInsertReactComponents).reduce(function (cprops, cpropName) {
// eslint-disable-next-line
cprops[cpropName] = getComponentFromMap$1({
rjx: { component: rjx.__dangerouslyInsertReactComponents[cpropName] },
reactComponents: _this3.reactComponents,
componentLibraries: _this3.componentLibraries
});
return cprops;
}, {});
}

/**
* Takes a function string and returns a function on either this.props or window. The function can only be 2 levels deep
* @param {Object} options
Expand Down Expand Up @@ -28657,7 +28681,7 @@ function getFunctionProps() {
* @returns {Object} resolved object of with React Components from a window property window.__rjx_custom_elements
*/
function getWindowComponents() {
var _this3 = this;
var _this4 = this;

var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var allProps = options.allProps,
Expand All @@ -28671,7 +28695,7 @@ function getWindowComponents() {
var windowKEY = typeof windowComponents[key] === 'string' ? windowComponents[key].replace(windowFuncPrefix + '.', '') : '';
if (typeof windowComponents[key] === 'string' && windowComponents[key].indexOf(windowFuncPrefix) !== -1 && typeof window.__rjx_custom_elements[windowKEY] === 'function') {
var windowComponentElement = window.__rjx_custom_elements[windowKEY];
var windowComponentProps = allProps['__windowComponentProps'] ? allProps['__windowComponentProps'] : _this3.props;
var windowComponentProps = allProps['__windowComponentProps'] ? allProps['__windowComponentProps'] : _this4.props;
allProps[key] = react.createElement(windowComponentElement, windowComponentProps, null);
}
});
Expand Down Expand Up @@ -28762,7 +28786,8 @@ function getComputedProps$1() {
//allowing javascript injections
var evalProps = rjx.__dangerouslyEvalProps || rjx.__dangerouslyBindEvalProps ? getEvalProps.call(this, { rjx: rjx }) : {};
var insertedComponents = rjx.__dangerouslyInsertComponents ? getComponentProps.call(this, { rjx: rjx, resources: resources, debug: debug }) : {};
var allProps = Object.assign({ key: renderIndex$$1 }, thisprops, rjx.props, asyncprops, windowprops, evalProps, insertedComponents);
var insertedReactComponents = rjx.__dangerouslyInsertReactComponents ? getReactComponentProps.call(this, { rjx: rjx, debug: debug }) : {};
var allProps = Object.assign({ key: renderIndex$$1 }, thisprops, rjx.props, asyncprops, windowprops, evalProps, insertedComponents, insertedReactComponents);
var computedProps = Object.assign({}, allProps, rjx.__functionProps ? getFunctionProps.call(this, { allProps: allProps, rjx: rjx }) : {}, rjx.__windowComponents ? getWindowComponents.call(this, { allProps: allProps, rjx: rjx }) : {});

return computedProps;
Expand All @@ -28778,6 +28803,7 @@ var rjxProps = Object.freeze({
getRJXProps: getRJXProps,
getEvalProps: getEvalProps,
getComponentProps: getComponentProps,
getReactComponentProps: getReactComponentProps,
getFunctionFromProps: getFunctionFromProps,
getFunctionProps: getFunctionProps,
getWindowComponents: getWindowComponents,
Expand Down
16 changes: 16 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<dt><a href="#getComponentProps">getComponentProps(options)</a> ⇒ <code>Object</code></dt>
<dd><p>Resolves rjx.__dangerouslyInsertComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.</p>
</dd>
<dt><a href="#getReactComponentProps">getReactComponentProps(options)</a> ⇒ <code>Object</code></dt>
<dd><p>Resolves rjx.__dangerouslyInsertReactComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.</p>
</dd>
<dt><a href="#getFunctionFromProps">getFunctionFromProps(options)</a> ⇒ <code>function</code></dt>
<dd><p>Takes a function string and returns a function on either this.props or window. The function can only be 2 levels deep</p>
</dd>
Expand Down Expand Up @@ -449,6 +452,19 @@ Resolves rjx.__dangerouslyInsertComponents into an object that turns each value
| options.rjx | <code>Object</code> | | Valid RJX JSON |
| [options.resources] | <code>Object</code> | <code>{}</code> | object to use for asyncprops, usually a result of an asynchronous call |

<a name="getReactComponentProps"></a>

## getReactComponentProps(options) ⇒ <code>Object</code>
Resolves rjx.__dangerouslyInsertReactComponents into an object that turns each value into a React components. This is typically used in a library like Recharts where you pass custom components for chart ticks or plot points.

**Kind**: global function
**Returns**: <code>Object</code> - resolved object of React Components

| Param | Type | Description |
| --- | --- | --- |
| options | <code>Object</code> | |
| options.rjx | <code>Object</code> | Valid RJX JSON // * @param {Object} [options.resources={}] - object to use for asyncprops, usually a result of an asynchronous call |

<a name="getFunctionFromProps"></a>

## getFunctionFromProps(options) ⇒ <code>function</code>
Expand Down
Loading

0 comments on commit df57d1e

Please sign in to comment.