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

eustatos / nexus-state / 29163188945

11 Jul 2026 06:17PM UTC coverage: 70.974% (+0.4%) from 70.575%
29163188945

Pull #79

github

web-flow
Merge fa8bcc630 into 86d24ec77
Pull Request #79: Feat/phase 14 cleanup and consolidation

2161 of 2534 branches covered (85.28%)

Branch coverage included in aggregate %.

8094 of 11915 relevant lines covered (67.93%)

4061.93 hits per line

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

91.75
/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 type { AtomContext } from '../reactive';
9
import { storeLogger as logger } from '../debug';
10

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

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

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

40
  /**
41
   * Execute onSet hooks
42
   * @param atom Atom being set
43
   * @param value Value to set
44
   * @param context Optional operation metadata
45
   * @returns Processed value
46
   * @complexity O(1) when no hooks registered, O(n) otherwise
47
   */
48
  executeOnSetHooks<T>(atom: Atom<any>, value: T, context?: AtomContext): T {
1✔
49
    if (this.hooks.length === 0) return value;
30,091✔
50

51
    let processedValue = value;
30,085✔
52

53
    for (const hooks of this.hooks) {
30,086✔
54
      if (hooks.onSet) {
50,098✔
55
        const result = hooks.onSet(atom, processedValue, context);
50,088✔
56
        if (result !== undefined) {
50,088✔
57
          processedValue = result;
50,079✔
58
        }
50,079✔
59
      }
50,088✔
60
    }
50,098✔
61

62
    return processedValue;
30,082✔
63
  }
30,091✔
64

65
  /**
66
   * Execute afterSet hooks
67
   * @param atom Atom that was set
68
   * @param value Final value
69
   * @param context Optional operation metadata
70
   * @complexity O(1) when no hooks registered, O(n) otherwise
71
   */
72
  executeAfterSetHooks<T>(atom: Atom<any>, value: T, context?: AtomContext): void {
1✔
73
    if (this.hooks.length === 0) return;
20,083✔
74

75
    for (const hooks of this.hooks) {
20,079✔
76
      if (hooks.afterSet) {
40,090✔
77
        hooks.afterSet(atom, value, context);
18✔
78
      }
18✔
79
    }
40,090✔
80
  }
20,083✔
81

82
  /**
83
   * Execute onGet hooks
84
   * @param atom Atom being read
85
   * @param value Current value
86
   * @returns Processed value
87
   * @complexity O(1) when no hooks registered, O(n) otherwise
88
   */
89
  executeOnGetHooks<T>(atom: Atom<any>, value: T): T {
1✔
90
    if (this.hooks.length === 0) return value;
67✔
91

92
    let processedValue = value;
60✔
93

94
    for (const hooks of this.hooks) {
61✔
95
      if (hooks.onGet) {
63✔
96
        processedValue = hooks.onGet(atom, processedValue);
8✔
97
      }
8✔
98
    }
63✔
99

100
    return processedValue;
60✔
101
  }
67✔
102

103
  /**
104
   * Get all applied plugins
105
   * @returns Array of plugins
106
   */
107
  getPlugins(): Plugin[] {
1✔
108
    return [...this.plugins];
2✔
109
  }
2✔
110

111
  /**
112
   * Get all hooks
113
   * @returns Array of hooks
114
   */
115
  getHooks(): PluginHooks[] {
1✔
116
    return [...this.hooks];
×
117
  }
×
118

119
  /**
120
   * Clear all plugins and hooks
121
   */
122
  clear(): void {
1✔
123
    this.plugins.length = 0;
3✔
124
    this.hooks.length = 0;
3✔
125
  }
3✔
126

127
  /**
128
   * Get plugin count
129
   * @returns Number of plugins
130
   */
131
  getPluginCount(): number {
1✔
132
    return this.plugins.length;
×
133
  }
×
134
}
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