Skip to content

Instantly share code, notes, and snippets.

@jordangarcia
Created December 4, 2018 20:07
Show Gist options
  • Save jordangarcia/9a0dd36697d84c3ae69fe8509e08e9cb to your computer and use it in GitHub Desktop.
Save jordangarcia/9a0dd36697d84c3ae69fe8509e08e9cb to your computer and use it in GitHub Desktop.
type ConditionOperator = 'and' | 'or' | 'not'
/**
* {
* operator: 'and',
* conditions: [
* {
* operator: 'or',
* conditions: [
<Condition>,
<Condition>,
* ]
* }
*
* ]
* }
*
*/
interface ConditionObject extends OperatorCondition {}
type OperatorCondition = {
operator: ConditionOperator
conditions: Condition[] | ConditionObject[]
}
type Condition = {
name: string
value: any
match_type: string
type: string
}
type ExperimentKey = string
type View = {
// conditions to see if a view is active
condition: OperatorCondition
// experiment keys that should try to activate for a view
experiments: ExperimentKey[]
}
type EnvironmentData = {
[key: string]: any
}
type EvaluatorFn = (condition: OperatorCondition, data: EnvironmentData) => boolean
type Change = {
config: object,
type: string,
}
type ActivationResult = {
variation: string,
changes: Change[],
}
interface Activator {
views: View[]
// list of activatorAttribute type to Evaluator
matchers: {
[type: string]: EvaluatorFn
}
activate({
environmentData: EnvironmentData,
userId: string,
userAttributes: object,
}) : ActivationResult[]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment