Module: web-toggle-point-react-pointcuts

Application code for creating a React pointcut.

Methods

(static) withTogglePoint(controlModule, featuresMap) → {external:React.Component}

A React Higher-Order-Component that wraps a base / control component and swaps in a variant when deemed appropriate by a context
Parameters:
Name Type Description
controlModule ReactComponentModuleNamespaceObject The control / base module
Properties
Name Type Description
default external:React.Component The control react component
featuresMap Map A map of features and their variants, with features as top-level keys and variants as nested keys with modules as the values.
Returns:
Wrapped react component
Type
external:React.Component

(static) withToggledHook(controlModule, featuresMap) → {external:React.Hook}

A React hook that wraps a base / control function or hook and swaps in a variant when deemed appropriate by a context
Parameters:
Name Type Description
controlModule ReactHookModuleNamespaceObject The control / base module
Properties
Name Type Description
default external:React.Hook | function The control react hook or function.
featuresMap Map A map of features and their variants, with features as top-level keys and variants as nested keys with modules as the values.
Returns:
Wrapped function / hook, as a hook (so must be applied in accordance with the rules of hooks)
Type
external:React.Hook

(inner) withTogglePointFactory(params) → {module:web-toggle-point-react-pointcuts.withTogglePoint}

A factory function used to create a withTogglePoint React Higher-Order-Component.
Parameters:
Name Type Description
params object parameters
Properties
Name Type Attributes Default Description
getActiveFeatures function a method to get active features. Called honouring the rules of hooks.
logError external:HostApplication.logError a method that logs errors
variantKey string <optional>
bucket A key use to identify a variant from the features data structure. Remaining members of the feature will be passed to the variant as props.
plugins Array.<module:web-toggle-point-react-pointcuts~plugin> <optional>
plugins to be used when toggling Will be used when a toggled component throws an error that can be caught by an ErrorBoundary. When errors are caught, the control/base code will be used as the fallback component.
Returns:
withTogglePoint React Higher-Order-Component.
Type
module:web-toggle-point-react-pointcuts.withTogglePoint
Example
const withTogglePoint = withTogglePointFactory({
  getActiveFeatures,
  plugins: [plugin1, plugin2, plugin3],
  logError: (error) => window.NREUM?.noticeError(error)
});
export default withTogglePoint(MyReactComponent);

(inner) withToggledHookFactory(params) → {module:web-toggle-point-react-pointcuts.withToggledHook}

A factory function used to create a withToggledHook React hook, wrapping an existing hook/function.
Parameters:
Name Type Description
params object parameters
Properties
Name Type Attributes Description
getActiveFeatures function a method to get active features, which is called honouring the rules of hooks.
plugins Array.<module:web-toggle-point-react-pointcuts~plugin> <optional>
plugins to be used when toggling
Returns:
withToggledHook hook function, use to wrap a function (either a hook itself, or a function that must be called wherever a hook can...).
Type
module:web-toggle-point-react-pointcuts.withToggledHook
Example
const getActiveFeatures = () => useContext(myContext);
const withToggledHook = withToggledHookFactory({
  getActiveFeatures,
  plugins: [plugin1, plugin2, plugin3]
});
export default withToggledHook(useMyHook);

Type Definitions

plugin

A plugin for the point cuts package
Type:
  • object
Properties:
Name Type Description
name string plugin name, used as a prefix when creating React Higher-Order-Components when toggling
onCodeSelected function hook to be called when a code selection is made