Skip to content

Commit eeebb2b

Browse files
author
James Fox
authored
maintanance (OptimizelyProvider): Replace react-broadcast with the native React context API (#12)
## Summary Replace usage of `react-broadcast` with the native React Context API. The `createContext` API appears to be identical in both cases, so this is just a simple swap with adding a type for the `OptimizelyContext` state. More here: https://reactjs.org/docs/context.html#reactcreatecontext
1 parent 1cae26a commit eeebb2b

File tree

6 files changed

+13
-43
lines changed

6 files changed

+13
-43
lines changed

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,6 @@ License: [MIT](https://github.com/taylorhakes/promise-polyfill/blob/master/LICEN
523523
Copyright © 2013-present, Facebook, Inc.
524524
License: [MIT](https://github.com/facebook/prop-types/blob/master/LICENSE)
525525

526-
[**react-broadcast**](https://github.com/ReactTraining/react-broadcast)
527-
Copyright © React Training 2016-2018
528-
License: [MIT](https://github.com/ReactTraining/react-broadcast/blob/master/LICENSE)
529-
530526
[**react-is**](https://github.com/facebook/react)
531527
Copyright © Facebook, Inc. and its affiliates.
532528
License: [MIT](https://github.com/facebook/react/blob/master/LICENSE)
@@ -547,11 +543,6 @@ License: [MIT](https://github.com/piotrwitek/utility-types/blob/master/LICENSE)
547543
Copyright © 2010-2016 Robert Kieffer and other contributors
548544
License: [MIT](https://github.com/kelektiv/node-uuid/blob/master/LICENSE.md)
549545

550-
[**warning**](https://github.com/BerkeleyTrue/warning)
551-
Copyright © 2013-present, Facebook, Inc.
552-
License: [MIT](https://github.com/BerkeleyTrue/warning/blob/master/LICENSE.md)
553-
554-
555546

556547
To regenerate the dependencies use by this package, run the following command:
557548

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"@optimizely/optimizely-sdk": "3.3.2",
3232
"hoist-non-react-statics": "^3.3.0",
3333
"prop-types": "^15.6.2",
34-
"react-broadcast": "0.7.1",
3534
"utility-types": "^2.1.0"
3635
},
3736
"peerDependencies": {
@@ -44,7 +43,6 @@
4443
"@types/jest": "^23.3.12",
4544
"@types/prop-types": "^15.5.6",
4645
"@types/react": "^16.7.18",
47-
"@types/react-broadcast": "^0.6.1",
4846
"enzyme": "^3.8.0",
4947
"enzyme-adapter-react-16": "^1.7.1",
5048
"jest": "^23.6.0",

src/Context.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
// @ts-ignore
17-
import { createContext } from 'react-broadcast'
16+
import { createContext } from 'react'
17+
import { ReactSDKClient } from './client'
1818

19-
const { Consumer, Provider } = createContext({
19+
export interface OptimizelyContext {
20+
optimizely: ReactSDKClient | null,
21+
isServerSide: boolean,
22+
timeout: number | undefined,
23+
}
24+
25+
const { Consumer, Provider } = createContext<OptimizelyContext>({
2026
optimizely: null,
2127
isServerSide: false,
2228
timeout: 0,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
export { OptimizelyContextConsumer, OptimizelyContextProvider } from './Context'
1617
export { OptimizelyProvider } from './Provider'
1718
export { OptimizelyFeature } from './Feature'
1819
export { withOptimizely, WithOptimizelyProps, WithoutOptimizelyProps } from './withOptimizely'

src/withOptimizely.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import * as React from 'react'
1717
import { Subtract } from 'utility-types'
1818

19-
import { OptimizelyContextConsumer } from './Context'
19+
import { OptimizelyContextConsumer, OptimizelyContext } from './Context'
2020
import { ReactSDKClient } from './client'
2121
import { hoistStaticsAndForwardRefs } from './utils'
2222

@@ -45,11 +45,7 @@ export function withOptimizely<P extends WithOptimizelyProps, R>(
4545
// https://github.com/microsoft/TypeScript/issues/28884
4646
return (
4747
<OptimizelyContextConsumer>
48-
{(value: {
49-
optimizely: ReactSDKClient
50-
isServerSide: boolean
51-
timeout: number | undefined
52-
}) => (
48+
{(value: OptimizelyContext) => (
5349
<Component
5450
{...rest as P}
5551
optimizelyReadyTimeout={value.timeout}

yarn.lock

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,6 @@
120120
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.1.tgz#f1a11e7babb0c3cad68100be381d1e064c68f1f6"
121121
integrity sha512-CFzn9idOEpHrgdw8JsoTkaDDyRWk1jrzIV8djzcgpq0y9tG4B4lFT+Nxh52DVpDXV+n4+NPNv7M1Dj5uMp6XFg==
122122

123-
"@types/react-broadcast@^0.6.1":
124-
version "0.6.1"
125-
resolved "https://registry.yarnpkg.com/@types/react-broadcast/-/react-broadcast-0.6.1.tgz#8b1bd9d37ff1db783db875228fefd26b6fbdfa90"
126-
integrity sha512-L5SENk1DYPNw5jaozAmx4ZoFl3zAlPqdDyTgq68S45ZZsL0YFimGSmqKo1NoBgqR+tpx6hTyZIeJ8p20U6rimw==
127-
dependencies:
128-
"@types/react" "*"
129-
130123
"@types/react@*", "@types/react@^16.7.18":
131124
version "16.8.19"
132125
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.19.tgz#629154ef05e2e1985cdde94477deefd823ad9be3"
@@ -3258,7 +3251,7 @@ prop-types-exact@^1.2.0:
32583251
object.assign "^4.1.0"
32593252
reflect.ownkeys "^0.2.0"
32603253

3261-
prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.7.2:
3254+
prop-types@^15.6.2, prop-types@^15.7.2:
32623255
version "15.7.2"
32633256
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
32643257
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -3331,14 +3324,6 @@ rc@^1.2.7:
33313324
minimist "^1.2.0"
33323325
strip-json-comments "~2.0.1"
33333326

3334-
3335-
version "0.7.1"
3336-
resolved "https://registry.yarnpkg.com/react-broadcast/-/react-broadcast-0.7.1.tgz#732c1f4d3c9dbb9dbf0b92540c7c2490fb746dfb"
3337-
integrity sha512-GhYhRBSSwys6dP++mlC2BNlKMgDfUCKAmOB7eyvgatsWk4TKY+sWVmkGkblP+QduHSBF/Rc+yTE2fZR+8+7Brw==
3338-
dependencies:
3339-
prop-types "^15.6.0"
3340-
warning "^3.0.0"
3341-
33423327
react-dom@^16.7.0:
33433328
version "16.8.6"
33443329
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.6.tgz#71d6303f631e8b0097f56165ef608f051ff6e10f"
@@ -4270,13 +4255,6 @@ walker@~1.0.5:
42704255
dependencies:
42714256
makeerror "1.0.x"
42724257

4273-
warning@^3.0.0:
4274-
version "3.0.0"
4275-
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
4276-
integrity sha1-MuU3fLVy3kqwR1O9+IIcAe1gW3w=
4277-
dependencies:
4278-
loose-envify "^1.0.0"
4279-
42804258
watch@~0.18.0:
42814259
version "0.18.0"
42824260
resolved "https://registry.yarnpkg.com/watch/-/watch-0.18.0.tgz#28095476c6df7c90c963138990c0a5423eb4b986"

0 commit comments

Comments
 (0)