Created
December 4, 2018 20:07
-
-
Save jordangarcia/bbc353fa4e921506d99bef1aa70e7483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
} | |
interface ActivationResult { | |
variation: string, | |
changes: Change[], | |
} | |
interface AppliedActivationResult extends ActivationResult { | |
// result of mapping applyFn on the change | |
appliedChanges: Array<any> | |
} | |
interface Activator { | |
views: View[] | |
// list of activatorAttribute type to Evaluator | |
matchers: { | |
[match_type: string]: EvaluatorFn | |
} | |
activate({ | |
environmentData: EnvironmentData, | |
userId: string, | |
userAttributes: object, | |
}) : ActivationResult[] | |
} | |
type ApplyFn = (change: Change) => any | |
interface ChangeApplier { | |
appliers: { | |
[change_type: string]: ApplyFn, | |
} | |
handleActivationResults(results: ActivationResult[]) : AppliedActivationResult[] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment