-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwithSplitFactory.tsx
More file actions
50 lines (46 loc) · 1.86 KB
/
withSplitFactory.tsx
File metadata and controls
50 lines (46 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as React from 'react';
import { ISplitFactoryChildProps } from './types';
import { SplitFactoryProvider } from './SplitFactoryProvider';
import { SplitClient } from './SplitClient';
/**
* High-Order Component for `SplitFactoryProvider`.
* The wrapped component receives all the props of the container,
* along with the passed props from the Split context (see `ISplitFactoryChildProps`).
*
* @param config - Config object used to instantiate a Split factory
* @param factory - Split factory instance to use instead of creating a new one with the config object.
* @param attributes - An object of type Attributes used to evaluate the feature flags.
*
* @deprecated `withSplitFactory` will be removed in a future major release. We recommend replacing it with the `SplitFactoryProvider` component.
*/
export function withSplitFactory(config?: SplitIO.IBrowserSettings, factory?: SplitIO.IBrowserSDK, attributes?: SplitIO.Attributes) {
return function withSplitFactoryHoc<OuterProps>(
WrappedComponent: React.ComponentType<OuterProps & ISplitFactoryChildProps>,
updateOnSdkUpdate?: boolean,
updateOnSdkTimedout?: boolean,
updateOnSdkReady?: boolean,
updateOnSdkReadyFromCache?: boolean,
) {
return function wrapper(props: OuterProps) {
return (
<SplitFactoryProvider
config={config}
factory={factory}>
<SplitClient
updateOnSdkUpdate={updateOnSdkUpdate}
updateOnSdkTimedout={updateOnSdkTimedout}
updateOnSdkReady={updateOnSdkReady}
updateOnSdkReadyFromCache={updateOnSdkReadyFromCache}
attributes={attributes}>
{(splitProps) => {
return (
<WrappedComponent
{...props} {...splitProps} />
);
}}
</SplitClient>
</SplitFactoryProvider>
);
};
};
}