react-ab-test
react-ab-test copied to clipboard
Typescript types
I'm working on creating a typings file for this project. I'm curious if you would like to include this in the project - or should I plan on uploading to DefinitelyTyped?
I have some experience with Flow, but haven't used TypeScript.
I think it would be a great addition, typings can be helpful even when not writing in TypeScript for the IntelliSense support.
In terms of changes, we just need to publish a new directory with type definitions (index.d.ts
) and then add a new types
entry to package.json
?
yes - that's pretty much it - i'll look to complete that work in the coming weeks. I've got the very basics in so far
Is there anything in progress with this issue?
I have two version i need to reconcile, should have time in the next couple weeks
If anyone needs it ASAP, here's what I threw together this morning. It's not perfect but it'll get you going at least.
Be aware that it's missing:
- Comments
- MixPanel types
- Segment types
There's probably a cleaner way to do the emitter and experiment debugger, but it works 🤷♂️
declare module '@marvelapp/react-ab-test' {
import * as React from 'react'
type ExperimentProps = {
name: string
userIdentifier?: string
defaultVariantName?: string
}
type VariantProps = {
name: string
}
export class Experiment extends React.Component<ExperimentProps, any> {}
export class Variant extends React.Component<VariantProps, any> {}
type EmitterCallback = (experimentName: string, variantName: string) => void
type Subscription = {
remove(): void
}
class Emitter {
emitWin(experimentName: string): void
addActiveVariantListener(experimentName?: string, callback: EmitterCallback): Subscription
addPlayListener(experimentName?: string, callback: EmitterCallback): Subscription
addWinListener(experimentName?: string, callback: EmitterCallback): Subscription
defineVariants(
experimentName: string,
variantNames: string[],
variantWeights: number[]
): void
setActiveVariant(experimentName: string, variantName: string): void
getActiveVariant(experimentName: string): string
calculateActiveVariant(
experimentName: string,
userIdentifier?: string,
defaultVariantName?: string
): string
getSortedVariants(experimentName: string)
}
class ExperimentDebugger {
setDebuggerAvailable(isAvailable: boolean): void
enable(): void
disable(): void
}
export const emitter = new Emitter()
export const experimentDebugger = new ExperimentDebugger()
}
I have two version i need to reconcile, should have time in the next couple weeks
Any advances in this matter so far?