Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 50d6a0f

Browse files
committed
Update README to not include support for decorators
1 parent f61c854 commit 50d6a0f

File tree

12 files changed

+85
-24
lines changed

12 files changed

+85
-24
lines changed

packages/js-web-sdk/packages/react-example-16/src/App.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,33 @@ import {
77
OptimizelyFeature,
88
OptimizelyExperiment,
99
OptimizelyVariation,
10+
withOptimizely,
1011
} from '@optimizely/react-sdk'
1112

13+
class TrackerButton extends React.Component {
14+
componentDidMount() {
15+
const { optimizely } = this.props
16+
console.log(optimizely)
17+
debugger
18+
}
19+
20+
render() {
21+
return <h3>{this.props.text}</h3>
22+
}
23+
}
24+
const OptimizelyTrackerButton = withOptimizely(TrackerButton)
25+
1226
class App extends Component {
1327
render() {
1428
return (
15-
<OptimizelyProvider optimizely={this.props.optimizely} timeout={200}>
29+
<OptimizelyProvider
30+
optimizely={this.props.optimizely}
31+
timeout={200}
32+
userId="jordan"
33+
>
1634
<div>
1735
<h1>Test app: React 16</h1>
36+
<OptimizelyTrackerButton text="Jordan" />
1837
<OptimizelyFeature feature="feature1">
1938
{(isEnabled, variables) => (
2039
<div>

packages/js-web-sdk/packages/react-example-ts/src/App.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@optimizely/react-sdk'
1414

1515
import { OptimizelySDKWrapper } from '@optimizely/js-web-sdk'
16+
import OTrackerButton from './TrackerButton'
1617

1718
interface AppProps {
1819
optimizely: OptimizelySDKWrapper
@@ -43,8 +44,16 @@ export default class App extends React.Component<AppProps> {
4344
const { optimizely } = this.props
4445

4546
return (
46-
<OptimizelyProvider optimizely={optimizely} timeout={200}>
47+
<OptimizelyProvider
48+
optimizely={optimizely}
49+
timeout={200}
50+
userId={`jordan${Date.now()}`}
51+
userAttributes={{ attribute1: 'yesssss' }}
52+
>
4753
<div className="App">
54+
<Example title="Decorator">
55+
<OTrackerButton text="jordan" />
56+
</Example>
4857
<Example title="Experiment (child render function)">
4958
<OptimizelyExperiment experiment="abtest1">
5059
{(variation: any) => {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react'
2+
import * as PropTypes from 'prop-types'
3+
4+
5+
import {
6+
withOptimizely,
7+
WithOptimizelyProps,
8+
} from '@optimizely/react-sdk'
9+
10+
11+
12+
interface AppProps extends WithOptimizelyProps {
13+
text: string
14+
}
15+
16+
export class TrackerButton extends React.Component<AppProps, any> {
17+
componentDidMount() {
18+
const { optimizely } = this.props
19+
console.log(optimizely)
20+
debugger;
21+
22+
}
23+
render() {
24+
25+
return (
26+
<h3>{this.props.text}</h3>
27+
)
28+
}
29+
}
30+
const OTrackerButton = withOptimizely(TrackerButton)
31+
export default OTrackerButton

packages/js-web-sdk/packages/react-example-ts/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"noImplicitThis": true,
1616
"noImplicitAny": true,
1717
"strictNullChecks": true,
18-
"suppressImplicitAnyIndexErrors": true
19-
},
18+
"suppressImplicitAnyIndexErrors": true,
19+
"experimentalDecorators": true
20+
},
2021
"exclude": [
2122
"node_modules",
2223
"build",

packages/js-web-sdk/packages/react-sdk/README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,11 @@ import { OptimizelyExperiment, OptimizelyVariation } from '@optimizely/react-sdk
195195

196196

197197
### Programmatic access inside component
198-
Any component under the `<OptimizelyProvider>` can get access to the optimizely js-web-sdk via the HoC / decorator `@withOptimizely`
198+
Any component under the `<OptimizelyProvider>` can get access to the optimizely js-web-sdk via the HoC `withOptimizely`
199199

200200
```jsx
201201
import { withOptimizely } from '@optimizely/react-sdk`
202202
203-
@withOptimizely
204203
class MyComp extends React.Component {
205204
constructor(props) {
206205
super(props)
@@ -218,20 +217,16 @@ class MyComp extends React.Component {
218217
}
219218
}
220219
221-
// or alternatively (if decorators arent enabled)
222220
const WrappedMyComponent = withOptimizely(MyComp)
223221
```
224222
225223
226-
227-
228224
## Tracking
229-
Tracking is easy with the `withOptimizely` HoC / decorator.
225+
Tracking is easy with the `withOptimizely` HoC.
230226
231227
```jsx
232228
import { withOptimizely } from '@optimizely/react-sdk`
233229
234-
@withOptimizely
235230
class SignupButton extends React.Component {
236231
onClick = () => {
237232
const { optimizely } = this.props
@@ -245,4 +240,6 @@ class SignupButton extends React.Component {
245240
</button>
246241
}
247242
}
243+
244+
const WrappedSignupButton = withOptimizely(SignupButton)
248245
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { OptimizelyProvider } from './Provider';
22
export { OptimizelyFeature } from './Feature';
3-
export { withOptimizely } from './withOptimizely';
3+
export { withOptimizely, WithOptimizelyProps } from './withOptimizely';
44
export { OptimizelyExperiment } from './Experiment';
55
export { OptimizelyVariation } from './Variation';

packages/js-web-sdk/packages/react-sdk/dist/react-sdk.browser.umd.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,8 @@
13351335
var finalUserAttributes = overrideAttributes !== undefined ? overrideAttributes : userAttributes;
13361336
return [finalUserId, finalUserAttributes || {}];
13371337
}
1338-
return __assign({}, instance, { activate: function (experimentKey, overrideUserId, overrideAttributes) {
1338+
return Object.assign(Object.create(instance), {
1339+
activate: function (experimentKey, overrideUserId, overrideAttributes) {
13391340
return instance.activate.apply(instance, [experimentKey].concat(getUserIdAndAttributes(overrideUserId, overrideAttributes)));
13401341
},
13411342
getVariation: function (experimentKey, overrideUserId, overrideAttributes) {
@@ -1371,7 +1372,8 @@
13711372
}
13721373
var _a = getUserIdAndAttributes(overrideUserId, overrideAttributes), userId = _a[0], attributes = _a[1];
13731374
return instance.track(eventKey, userId, attributes, eventTags);
1374-
} });
1375+
},
1376+
});
13751377
}
13761378

13771379
var OptimizelyProvider = /** @class */ (function (_super) {

packages/js-web-sdk/packages/react-sdk/dist/react-sdk.browser.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/js-web-sdk/packages/react-sdk/dist/react-sdk.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function createUserWrapper(_a) {
7474
var finalUserAttributes = overrideAttributes !== undefined ? overrideAttributes : userAttributes;
7575
return [finalUserId, finalUserAttributes || {}];
7676
}
77-
return __assign({}, instance, { activate: function (experimentKey, overrideUserId, overrideAttributes) {
77+
return Object.assign(Object.create(instance), {
78+
activate: function (experimentKey, overrideUserId, overrideAttributes) {
7879
return instance.activate.apply(instance, [experimentKey].concat(getUserIdAndAttributes(overrideUserId, overrideAttributes)));
7980
},
8081
getVariation: function (experimentKey, overrideUserId, overrideAttributes) {
@@ -110,7 +111,8 @@ function createUserWrapper(_a) {
110111
}
111112
var _a = getUserIdAndAttributes(overrideUserId, overrideAttributes), userId = _a[0], attributes = _a[1];
112113
return instance.track(eventKey, userId, attributes, eventTags);
113-
} });
114+
},
115+
});
114116
}
115117

116118
var OptimizelyProvider = /** @class */ (function (_super) {

packages/js-web-sdk/packages/react-sdk/dist/react-sdk.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ function createUserWrapper(_a) {
7070
var finalUserAttributes = overrideAttributes !== undefined ? overrideAttributes : userAttributes;
7171
return [finalUserId, finalUserAttributes || {}];
7272
}
73-
return __assign({}, instance, { activate: function (experimentKey, overrideUserId, overrideAttributes) {
73+
return Object.assign(Object.create(instance), {
74+
activate: function (experimentKey, overrideUserId, overrideAttributes) {
7475
return instance.activate.apply(instance, [experimentKey].concat(getUserIdAndAttributes(overrideUserId, overrideAttributes)));
7576
},
7677
getVariation: function (experimentKey, overrideUserId, overrideAttributes) {
@@ -106,7 +107,8 @@ function createUserWrapper(_a) {
106107
}
107108
var _a = getUserIdAndAttributes(overrideUserId, overrideAttributes), userId = _a[0], attributes = _a[1];
108109
return instance.track(eventKey, userId, attributes, eventTags);
109-
} });
110+
},
111+
});
110112
}
111113

112114
var OptimizelyProvider = /** @class */ (function (_super) {

0 commit comments

Comments
 (0)