Concepts
Lookups
Lookups allow you to read information on demand via installed modules in your application.
Anatomy of a lookup#
A lookup is a form of a source that can be used in conditions and transforms.
It's ultimately expressed as a string, which is the module name followed by a dot separated path to the property you want to read.
Example of a lookup inside a condition:
conditions: - lookup: localstorage.someKeyHere operator: equals value: someValueHere
Module setup#
We can install the module module-localstorage in our application to give a demo:
$ npm install --save @eventvisor/module-localstorage
And then set it up when initializing the SDK:
import { createInstance } from "@eventvisor/sdk";import { createLocalStorageModule } from "@eventvisor/module-localstorage";const eventvisor = createInstance({ modules: [ createLocalStorageModule(), ],});
Usage example#
Now that we know our application is set up with the module, we can use localstorage as a lookup in one of our conditions:
conditions: - lookup: localstorage.myKey operator: equals value: myValue
A real-world example could be storing if the user has consented to storing their data in localStorage or not for GDPR compliance:
conditions: - lookup: localstorage.gdprConsent operator: equals value: true
Creating custom lookups#
To create a custom lookup, you can create a new custom module with at least the lookup
method implemented:
Defining module#
export function createCustomModule() { return { name: "custom", lookup: async ({ key }) => { return "some value"; }, };};
SDK setup#
And then set it up when initializing the SDK:
import { createInstance } from "@eventvisor/sdk";import { createCustomModule } from "./custom";const eventvisor = createInstance({ modules: [ createCustomModule(), ],});
Lookup usage#
Later in your definitions, you can use the custom lookup like this:
conditions: - lookup: custom.myKey operator: equals value: myValue