Skip to content

fix: Allow Integration<T> constructor to have arguments #2115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2019

Conversation

sod
Copy link
Contributor

@sod sod commented Jun 11, 2019

Relax the constructor signature so it may have arguments. Someone might wanna do:

class MyCustomIntegration implements Integration {
    public static id = 'MyCustomIntegration';
    public name = MyCustomIntegration.id;

    constructor(public options: {patterns: RegExp[]}) {
    }

    public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
        addGlobalEventProcessor((event: Event) => {
            const self = getCurrentHub().getIntegration(MyCustomIntegration);

            if (self && self.options.patterns.some(rx => rx.test(/* ... */)) {
                return null;
            }

            return event;
        });
    }
}

But getIntegration(MyCustomIntegration) complains, that MyCustomIntegration doesn't match the signature, as arguments in the constructor aren't allowed.

@sod sod requested a review from kamilogorek as a code owner June 11, 2019 16:56
Copy link
Member

@HazAT HazAT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool thx!

@HazAT HazAT merged commit 29c2f6f into getsentry:master Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants