ensure
Import
import ensure from '@redux-beacon/ensure';Syntax
ensure(validator, eventDef)Parameters
Validator
type Validator = (event: any[]) => boolean;Example
Last updated
import ensure from '@redux-beacon/ensure';ensure(validator, eventDef)type Validator = (event: any[]) => boolean;Last updated
import joi from 'joi';
import ensure from '@redux-beacon/ensure'
const pageview = (action, prevState) => ({
hitType: 'pageview',
route: action.payload.location.pathname,
referrer: prevState.currentRoute,
});
// Returns true if the event matches the schema
const isValidPageView = event =>
!joi.validate(event, joi.object().keys({
hitType: joi.string().only('pageview').required(),
page: joi.string().disallow('/404'),
title: joi.string(),
location: joi.string(),
})).error;
const eventsMap = {
LOCATION_CHANGE: ensure(isValidPageView, pageview)
};