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

eustatos / nexus-state / 22889594323

10 Mar 2026 06:09AM UTC coverage: 75.366% (+7.2%) from 68.177%
22889594323

push

github

web-flow
fix(react,core): fix tests (#42)

4953 of 5766 branches covered (85.9%)

Branch coverage included in aggregate %.

8899 of 11343 new or added lines in 134 files covered. (78.45%)

252 existing lines in 21 files now uncovered.

18289 of 25073 relevant lines covered (72.94%)

94.28 hits per line

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

86.25
/packages/core/src/store/PluginSystem.ts
1
/**
1✔
2
 * PluginSystem - Manages store plugins and hooks
3
 *
4
 * Handles plugin registration and hook execution.
5
 */
6

7
import type { Store, Plugin, PluginHooks, Atom, ActionMetadata } from '../types';
8
import { storeLogger as logger } from '../debug';
9

10
/**
11
 * PluginSystem provides plugin management
12
 */
13
export class PluginSystem {
1✔
14
  private plugins: Plugin[] = [];
448✔
15
  private hooks: PluginHooks[] = [];
448✔
16

17
  /**
18
   * Apply a plugin to the store
19
   * @param plugin Plugin to apply
20
   * @param store Store instance
21
   */
22
  applyPlugin(plugin: Plugin, store: Store): void {
1✔
23
    this.plugins.push(plugin);
37✔
24

25
    try {
37✔
26
      const hooks = plugin(store);
37✔
27
      if (hooks && typeof hooks === 'object') {
37✔
28
        this.hooks.push(hooks);
30✔
29
        logger.log('[PluginSystem] Applied plugin with hooks');
30✔
30
      } else {
37✔
31
        logger.log('[PluginSystem] Applied plugin without hooks');
7✔
32
      }
7✔
33
    } catch (error) {
37!
NEW
34
      logger.error('[PluginSystem] Plugin application error:', error);
×
NEW
35
      throw error;
×
NEW
36
    }
×
37
  }
37✔
38

39
  /**
40
   * Execute onSet hooks
41
   * @param atom Atom being set
42
   * @param value Value to set
43
   * @returns Processed value
44
   */
45
  executeOnSetHooks<T>(atom: Atom<any>, value: T): T {
1✔
46
    let processedValue = value;
462✔
47

48
    for (const hooks of this.hooks) {
462✔
49
      if (hooks.onSet) {
26✔
50
        const result = hooks.onSet(atom, processedValue);
20✔
51
        if (result !== undefined) {
20✔
52
          processedValue = result;
15✔
53
        }
15✔
54
      }
20✔
55
    }
26✔
56

57
    return processedValue;
461✔
58
  }
462✔
59

60
  /**
61
   * Execute afterSet hooks
62
   * @param atom Atom that was set
63
   * @param value Final value
64
   */
65
  executeAfterSetHooks<T>(atom: Atom<any>, value: T): void {
1✔
66
    for (const hooks of this.hooks) {
461✔
67
      if (hooks.afterSet) {
25✔
68
        hooks.afterSet(atom, value);
13✔
69
      }
13✔
70
    }
25✔
71
  }
461✔
72

73
  /**
74
   * Execute onGet hooks
75
   * @param atom Atom being read
76
   * @param value Current value
77
   * @returns Processed value
78
   */
79
  executeOnGetHooks<T>(atom: Atom<any>, value: T): T {
1✔
80
    let processedValue = value;
1,376✔
81

82
    for (const hooks of this.hooks) {
1,376✔
83
      if (hooks.onGet) {
16✔
84
        processedValue = hooks.onGet(atom, processedValue);
5✔
85
      }
5✔
86
    }
16✔
87

88
    return processedValue;
1,376✔
89
  }
1,376✔
90

91
  /**
92
   * Get all applied plugins
93
   * @returns Array of plugins
94
   */
95
  getPlugins(): Plugin[] {
1✔
96
    return [...this.plugins];
2✔
97
  }
2✔
98

99
  /**
100
   * Get all hooks
101
   * @returns Array of hooks
102
   */
103
  getHooks(): PluginHooks[] {
1✔
NEW
104
    return [...this.hooks];
×
NEW
105
  }
×
106

107
  /**
108
   * Clear all plugins and hooks
109
   */
110
  clear(): void {
1✔
NEW
111
    this.plugins.length = 0;
×
NEW
112
    this.hooks.length = 0;
×
NEW
113
  }
×
114

115
  /**
116
   * Get plugin count
117
   * @returns Number of plugins
118
   */
119
  getPluginCount(): number {
1✔
NEW
120
    return this.plugins.length;
×
NEW
121
  }
×
122
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc