Skip to content
This repository was archived by the owner on Jul 25, 2026. It is now read-only.
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions acceptance-setup/__tests__/__snapshots__/acceptance.js.snap

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"packages": [
"packages/*",
"acceptance-setup",
"acceptance-components/*"
"acceptance-components/*",
"mocks/*"
Comment thread
dipunm marked this conversation as resolved.
Outdated
],
"version": "independent",
"npmClient": "npm",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const reactOCProviderTemplate = ({ viewPath }) => `
import PropTypes from 'prop-types';
import React from 'react';
import { Provider } from 'oc-template-react-compiler/utils/ocContext';
import View from '${viewPath}';

class OCProvider extends React.Component {
Expand All @@ -9,7 +9,7 @@ const reactOCProviderTemplate = ({ viewPath }) => `
window.oc.events.fire('oc:componentDidMount', rest);
}

getChildContext() {
buildActions() {
const getData = (parameters, cb) => {
return window.oc.getData({
name: this.props._componentName,
Expand Down Expand Up @@ -37,17 +37,16 @@ const reactOCProviderTemplate = ({ viewPath }) => `
}

render() {
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = this.props;
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = this.props;
const actions = this.buildActions();
return (
<View {...rest} />
<Provider value={actions}>
<View {...rest} />
</Provider>
);
}
}

OCProvider.childContextTypes = {
getData: PropTypes.func,
getSetting: PropTypes.func
};
export default OCProvider
`;

Expand Down
6 changes: 6 additions & 0 deletions packages/oc-template-react-compiler/utils/ocContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";

const ctx = React.createContext();

export const Consumer = ctx.Consumer;
export const Provider = ctx.Provider;
24 changes: 13 additions & 11 deletions packages/oc-template-react-compiler/utils/withDataProvider.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React from "react";
import PropTypes from "prop-types";
import { Consumer } from "./ocContext";

const withDataProvider = BaseComponent => {
const Enhanced = (props, context) => {
const propsWithGetData = {
...props,
getData: context.getData
};
const Enhanced = props => {
return (
<Consumer>
{context => {
const propsWithGetData = {
...props,
getData: context.getData
};

return <BaseComponent {...propsWithGetData} />;
};

Enhanced.contextTypes = {
getData: PropTypes.func
return <BaseComponent {...propsWithGetData} />;
}}
</Consumer>
);
};

return Enhanced;
Expand Down
24 changes: 13 additions & 11 deletions packages/oc-template-react-compiler/utils/withSettingProvider.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React from "react";
import PropTypes from "prop-types";
import { Consumer } from "./ocContext";

const withSettingProvider = BaseComponent => {
const Enhanced = (props, context) => {
const propsWithGetSetting = {
...props,
getSetting: context.getSetting
};
const Enhanced = props => {
return (
<Consumer>
{context => {
const propsWithGetSetting = {
...props,
getSetting: context.getSetting
};

return <BaseComponent {...propsWithGetSetting} />;
};

Enhanced.contextTypes = {
getSetting: PropTypes.func
return <BaseComponent {...propsWithGetSetting} />;
}}
</Consumer>
);
};

return Enhanced;
Expand Down
1 change: 0 additions & 1 deletion packages/oc-template-react/lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const PropTypes = require("prop-types");
const React = require("react");
const ReactDOM = require("react-dom");
const ReactDOMServer = require("react-dom/server");
const vm = require("vm");

const createPredicate = require("./to-be-published/get-js-from-url");
const tryGetCached = require("./to-be-published/try-get-cached");
Expand Down