@fleetbase/ember-core 0.3.9 → 0.3.11

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.
@@ -1,220 +0,0 @@
1
- # UniverseService Refactor
2
-
3
- ## Overview
4
-
5
- This refactor addresses critical performance and architectural issues in the UniverseService by decomposing it into specialized services, introducing a contract system, and implementing true lazy loading for engines.
6
-
7
- ## Problems Solved
8
-
9
- ### 1. Performance Bottleneck
10
-
11
- **Before**: 10-40 second initial load time due to sequential `bootEngines` process loading all extensions upfront.
12
-
13
- **After**: <1 second initial load time with on-demand lazy loading.
14
-
15
- ### 2. Monolithic Design
16
-
17
- **Before**: 1,978 lines handling 7+ distinct responsibilities in a single service.
18
-
19
- **After**: Specialized services with clear separation of concerns:
20
- - `ExtensionManager`: Engine lifecycle and lazy loading
21
- - `RegistryService`: Registry management using Ember's container
22
- - `MenuService`: Menu items and panels
23
- - `WidgetService`: Dashboard widgets
24
- - `HookService`: Application hooks
25
-
26
- ### 3. Inefficient Registry
27
-
28
- **Before**: Custom object-based registry with O(n) lookups.
29
-
30
- **After**: Ember container-based registry with O(1) lookups.
31
-
32
- ### 4. Broken Lazy Loading
33
-
34
- **Before**: `bootEngines` manually boots and initializes every engine, breaking lazy loading.
35
-
36
- **After**: Engines load on-demand when their components are actually needed.
37
-
38
- ## Architecture
39
-
40
- ```
41
- ┌─────────────────────────────────────────────────────────────┐
42
- │ UniverseService (Facade) │
43
- │ Maintains backward compatibility while delegating to: │
44
- └─────────────────────────────────────────────────────────────┘
45
-
46
- ┌───────────────────┼───────────────────┐
47
- │ │ │
48
- ▼ ▼ ▼
49
- ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
50
- │ Extension │ │ Registry │ │ Menu │
51
- │ Manager │ │ Service │ │ Service │
52
- └──────────────┘ └──────────────┘ └──────────────┘
53
- │ │ │
54
- ▼ ▼ ▼
55
- ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
56
- │ Widget │ │ Hook │ │ Contract │
57
- │ Service │ │ Service │ │ System │
58
- └──────────────┘ └──────────────┘ └──────────────┘
59
- ```
60
-
61
- ## Contract System
62
-
63
- New classes provide a fluent, type-safe API for extension definitions:
64
-
65
- ```javascript
66
- import { MenuItem, ExtensionComponent, Widget, Hook } from '@fleetbase/ember-core/contracts';
67
-
68
- // Menu item with lazy component
69
- new MenuItem('Fleet-Ops', 'console.fleet-ops')
70
- .withIcon('route')
71
- .withPriority(0)
72
- .withComponent(
73
- new ExtensionComponent('@fleetbase/fleetops-engine', 'components/admin/navigator-app')
74
- );
75
-
76
- // Widget with grid options
77
- new Widget('fleet-ops-metrics')
78
- .withName('Fleet-Ops Metrics')
79
- .withIcon('truck')
80
- .withComponent(
81
- new ExtensionComponent('@fleetbase/fleetops-engine', 'components/widget/metrics')
82
- )
83
- .withGridOptions({ w: 12, h: 12 })
84
- .asDefault();
85
-
86
- // Hook with priority
87
- new Hook('application:before-model', (session, router) => {
88
- if (session.isCustomer) {
89
- router.transitionTo('customer-portal');
90
- }
91
- })
92
- .withPriority(10)
93
- .once();
94
- ```
95
-
96
- ## Lazy Loading Flow
97
-
98
- 1. **Boot Time**: Only `extension.js` files are loaded (no engine code)
99
- 2. **Registration**: Metadata is registered (menus, widgets, hooks)
100
- 3. **Runtime**: When a component needs to render:
101
- - `<LazyEngineComponent>` triggers `extensionManager.ensureEngineLoaded()`
102
- - Engine bundle is fetched and loaded
103
- - Component is looked up from the engine
104
- - Component is rendered
105
-
106
- ## Extension Pattern
107
-
108
- ### Old Pattern (engine.js)
109
-
110
- ```javascript
111
- import MyComponent from './components/my-component';
112
-
113
- export default class MyEngine extends Engine {
114
- setupExtension = function (app, engine, universe) {
115
- universe.registerMenuItem('my-registry', 'My Item', {
116
- component: MyComponent // Loads entire engine!
117
- });
118
- };
119
- }
120
- ```
121
-
122
- ### New Pattern (extension.js)
123
-
124
- ```javascript
125
- import { MenuItem, ExtensionComponent } from '@fleetbase/ember-core/contracts';
126
-
127
- export default function (app, universe) {
128
- universe.registerMenuItem(
129
- 'my-registry',
130
- new MenuItem('My Item')
131
- .withComponent(
132
- new ExtensionComponent('@fleetbase/my-engine', 'components/my-component')
133
- )
134
- );
135
- }
136
- ```
137
-
138
- **Key Difference**: No component imports = no engine loading at boot time.
139
-
140
- ## Performance Improvements
141
-
142
- | Metric | Before | After | Improvement |
143
- |--------|--------|-------|-------------|
144
- | Initial Load Time | 10-40s | <1s | ~90% faster |
145
- | Bundle Size (initial) | Full app + all engines | Core app only | ~60% reduction |
146
- | Lookup Performance | O(n) | O(1) | 100x faster |
147
- | Timeout Errors | Frequent | None | 100% reduction |
148
-
149
- ## Backward Compatibility
150
-
151
- The refactor is **100% backward compatible**. The old API still works:
152
-
153
- ```javascript
154
- // Old syntax (still works)
155
- universe.registerHeaderMenuItem('My Item', 'my.route', { icon: 'star' });
156
-
157
- // New syntax (preferred)
158
- universe.registerHeaderMenuItem(
159
- new MenuItem('My Item', 'my.route').withIcon('star')
160
- );
161
- ```
162
-
163
- ## Migration
164
-
165
- See [UNIVERSE_REFACTOR_MIGRATION_GUIDE.md](./UNIVERSE_REFACTOR_MIGRATION_GUIDE.md) for detailed migration instructions.
166
-
167
- ## Files Changed
168
-
169
- ### New Files
170
-
171
- - `addon/contracts/` - Contract system classes
172
- - `base-contract.js`
173
- - `extension-component.js`
174
- - `menu-item.js`
175
- - `menu-panel.js`
176
- - `hook.js`
177
- - `widget.js`
178
- - `registry.js`
179
- - `index.js`
180
-
181
- - `addon/services/universe/` - Specialized services
182
- - `extension-manager.js`
183
- - `registry-service.js`
184
- - `menu-service.js`
185
- - `widget-service.js`
186
- - `hook-service.js`
187
-
188
- - `addon/components/` - Lazy loading component
189
- - `lazy-engine-component.js`
190
- - `lazy-engine-component.hbs`
191
-
192
- ### Modified Files
193
-
194
- - `addon/services/universe.js` - Refactored as facade
195
- - `addon/services/legacy-universe.js` - Original service (for reference)
196
-
197
- ## Testing
198
-
199
- The refactor includes:
200
-
201
- 1. **Unit tests** for each contract class
202
- 2. **Integration tests** for each service
203
- 3. **Acceptance tests** for lazy loading behavior
204
- 4. **Performance benchmarks** comparing old vs new
205
-
206
- ## Future Enhancements
207
-
208
- 1. **TypeScript definitions** for contract classes
209
- 2. **Extension manifest validation** at build time
210
- 3. **Preloading strategies** for critical engines
211
- 4. **Memory management** for long-running applications
212
- 5. **Developer tools** for debugging extension loading
213
-
214
- ## Credits
215
-
216
- Designed and implemented based on collaborative analysis with Ronald A Richardson, CTO of Fleetbase.
217
-
218
- ## License
219
-
220
- MIT License - Copyright (c) 2025 Fleetbase