• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / roku-debug / #2011

pending completion
#2011

push

web-flow
Merge bb51a5c85 into f30a7deaa

1834 of 2724 branches covered (67.33%)

Branch coverage included in aggregate %.

1866 of 1866 new or added lines in 41 files covered. (100.0%)

3394 of 4571 relevant lines covered (74.25%)

25.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/debugProtocol/PluginInterface.ts
1
// inspiration: https://github.com/andywer/typed-emitter/blob/master/index.d.ts
2
export type Arguments<T> = [T] extends [(...args: infer U) => any]
3
    ? U
4
    : [T] extends [void] ? [] : [T];
5

6
export default class PluginInterface<TPlugin> {
1✔
7
    constructor(
8
        plugins = [] as TPlugin[]
122✔
9
    ) {
10
        for (const plugin of plugins ?? []) {
122!
11
            this.add(plugin);
×
12
        }
13
    }
14

15
    private plugins: Array<PluginContainer<TPlugin>> = [];
122✔
16

17
    /**
18
     * Call `event` on plugins
19
     */
20
    public async emit<K extends keyof TPlugin & string>(eventName: K, event: Arguments<TPlugin[K]>[0]) {
21
        for (let { plugin } of this.plugins) {
1,272✔
22
            if ((plugin as any)[eventName]) {
1,271✔
23
                await Promise.resolve((plugin as any)[eventName](event));
374✔
24
            }
25
        }
26
        return event;
1,272✔
27
    }
28

29
    /**
30
     * Add a plugin to the end of the list of plugins
31
     */
32
    public add<T extends TPlugin = TPlugin>(plugin: T, priority = 1) {
57✔
33
        const container = {
121✔
34
            plugin: plugin,
35
            priority: priority
36
        };
37
        this.plugins.push(container);
121✔
38

39
        //sort the plugins by priority
40
        this.plugins.sort((a, b) => {
121✔
41
            return a.priority - b.priority;
×
42
        });
43

44
        return plugin;
121✔
45
    }
46

47
    /**
48
     * Remove the specified plugin
49
     */
50
    public remove<T extends TPlugin = TPlugin>(plugin: T) {
51
        for (let i = this.plugins.length - 1; i >= 0; i--) {
×
52
            if (this.plugins[i].plugin === plugin) {
×
53
                this.plugins.splice(i, 1);
×
54
            }
55
        }
56
    }
57

58
    /**
59
     * Remove all plugins
60
     */
61
    public clear() {
62
        this.plugins = [];
×
63
    }
64
}
65

66
interface PluginContainer<TPlugin> {
67
    plugin: TPlugin;
68
    priority: number;
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc