vgapp 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,15 +11,6 @@ VGApp — набор фронтенд‑модулей (UI‑компонент
11
11
  npm i vgapp
12
12
  ```
13
13
 
14
- Локально из соседнего репозитория:
15
- ```json
16
- {
17
- "dependencies": {
18
- "vgapp": "file:../vegas-app"
19
- }
20
- }
21
- ```
22
-
23
14
  ## API
24
15
  ```js
25
16
  import vgapp from 'vgapp';
@@ -28,7 +19,7 @@ vgapp.boot();
28
19
  ```
29
20
 
30
21
  - `vgapp` экспортируется как singleton app.
31
- - `vgapp.register()` регистрирует модули по их статическому `NAME`.
22
+ - `vgapp.register()` использует единый контракт: `register(name, Module)`.
32
23
  - `vgapp.boot()` вызывает общий boot-контракт модуля.
33
24
  - У модулей со своим `initAll()` boot использует его автоматически.
34
25
 
@@ -39,7 +30,8 @@ import { VGApp, VGModal, VGTooltip } from 'vgapp';
39
30
  const app = new VGApp();
40
31
 
41
32
  app
42
- .register(VGModal, VGTooltip)
33
+ .register(VGModal.NAME, VGModal)
34
+ .register(VGTooltip.NAME, VGTooltip)
43
35
  .boot();
44
36
  ```
45
37
 
@@ -116,7 +108,8 @@ import 'vgapp/build/vgapp.css';
116
108
  const app = new VGApp();
117
109
 
118
110
  app
119
- .register(VGModal, VGTooltip)
111
+ .register(VGModal.NAME, VGModal)
112
+ .register(VGTooltip.NAME, VGTooltip)
120
113
  .boot();
121
114
  ```
122
115
 
package/app/vgapp.js CHANGED
@@ -19,40 +19,26 @@ import VGTabs from './modules/vgtabs';
19
19
  import VGToast from './modules/vgtoast';
20
20
  import VGTooltip from './modules/vgtooltip';
21
21
 
22
- class VGApp {
23
- constructor(options = {}) {
24
- this._modules = new Map();
22
+ class VGApp {
23
+ constructor(options = {}) {
24
+ this._modules = new Map();
25
25
  this._initializer = typeof options.initializer === 'function'
26
26
  ? options.initializer
27
27
  : null;
28
- this._isInitialized = false;
29
- }
30
-
31
- register(...entries) {
32
- const modules = entries.flatMap((entry) => {
33
- if (Array.isArray(entry)) {
34
- return entry;
35
- }
36
-
37
- return entry ? [entry] : [];
38
- });
39
-
40
- for (const Module of modules) {
41
- const candidate = Module?.default ?? Module;
42
- const name = String(candidate?.NAME || '').trim();
43
-
44
- if (!name) {
45
- const moduleKeys = Module && typeof Module === 'object'
46
- ? Object.keys(Module).join(', ')
47
- : '';
48
- throw new Error(`VGApp.register() ожидает модуль со статическим NAME. Получено: ${moduleKeys || typeof Module}`);
49
- }
50
-
51
- this._modules.set(name, candidate);
52
- }
53
-
54
- return this;
55
- }
28
+ this._isInitialized = false;
29
+ }
30
+
31
+ register(name, Module) {
32
+ const normalizedName = String(name || '').trim();
33
+ const candidate = this._resolveModuleCandidate(Module);
34
+
35
+ if (!normalizedName) {
36
+ throw new Error('VGApp.register() ожидает строковое имя модуля первым аргументом.');
37
+ }
38
+
39
+ this._modules.set(normalizedName, candidate);
40
+ return this;
41
+ }
56
42
 
57
43
  boot(config = {}) {
58
44
  this._ensureInitialized();
@@ -74,14 +60,24 @@ class VGApp {
74
60
  return this._modules.get(String(name).trim());
75
61
  }
76
62
 
77
- has(name) {
78
- this._ensureInitialized();
79
- return this._modules.has(String(name).trim());
80
- }
81
-
82
- _resolveModuleConfig(name, config) {
83
- if (!config || typeof config !== 'object') {
84
- return undefined;
63
+ has(name) {
64
+ this._ensureInitialized();
65
+ return this._modules.has(String(name).trim());
66
+ }
67
+
68
+ _resolveModuleCandidate(Module) {
69
+ const candidate = Module?.default ?? Module;
70
+
71
+ if (!candidate) {
72
+ throw new Error('VGApp.register() ожидает валидный модуль.');
73
+ }
74
+
75
+ return candidate;
76
+ }
77
+
78
+ _resolveModuleConfig(name, config) {
79
+ if (!config || typeof config !== 'object') {
80
+ return undefined;
85
81
  }
86
82
 
87
83
  return Object.prototype.hasOwnProperty.call(config, name)
@@ -99,7 +95,7 @@ class VGApp {
99
95
  }
100
96
  }
101
97
 
102
- const defaultModules = [
98
+ const defaultModules = [
103
99
  VGAlert,
104
100
  VGCollapse,
105
101
  VGDropdown,
@@ -119,12 +115,16 @@ const defaultModules = [
119
115
  VGSpy,
120
116
  VGTabs,
121
117
  VGToast,
122
- VGTooltip,
123
- ];
124
-
125
- const vgapp = new VGApp({
126
- initializer: (app) => app.register(defaultModules),
127
- });
118
+ VGTooltip,
119
+ ];
120
+
121
+ const vgapp = new VGApp({
122
+ initializer: (app) => {
123
+ defaultModules.forEach((Module) => {
124
+ app.register(Module.NAME, Module);
125
+ });
126
+ },
127
+ });
128
128
 
129
129
  export { VGApp, vgapp };
130
130
  export default vgapp;