2021-08-19 11:42:49 -04:00
|
|
|
import { createContext, useContext, useMemo } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import getMeta from '../../utils/meta'
|
|
|
|
|
|
|
|
export const SplitTestContext = createContext()
|
|
|
|
|
|
|
|
SplitTestContext.Provider.propTypes = {
|
|
|
|
value: PropTypes.shape({
|
|
|
|
splitTestVariants: PropTypes.object.isRequired,
|
2022-07-25 08:33:39 -04:00
|
|
|
splitTestInfo: PropTypes.object.isRequired,
|
2021-08-19 11:42:49 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
export function SplitTestProvider({ children }) {
|
|
|
|
const value = useMemo(
|
|
|
|
() => ({
|
|
|
|
splitTestVariants: getMeta('ol-splitTestVariants') || {},
|
2022-07-25 08:33:39 -04:00
|
|
|
splitTestInfo: getMeta('ol-splitTestInfo') || {},
|
2021-08-19 11:42:49 -04:00
|
|
|
}),
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SplitTestContext.Provider value={value}>
|
|
|
|
{children}
|
|
|
|
</SplitTestContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
SplitTestProvider.propTypes = {
|
|
|
|
children: PropTypes.any,
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useSplitTestContext(propTypes) {
|
|
|
|
const context = useContext(SplitTestContext)
|
|
|
|
|
|
|
|
PropTypes.checkPropTypes(
|
|
|
|
propTypes,
|
|
|
|
context,
|
|
|
|
'data',
|
|
|
|
'SplitTestContext.Provider'
|
|
|
|
)
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|