wu-framework 1.0.1 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wu-framework",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "🚀 Universal Microfrontends Framework - Framework agnostic, zero config, Shadow DOM isolation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -34,21 +34,34 @@ export class WuRegistry {
34
34
  }
35
35
  });
36
36
 
37
- // Exponer API global para microfrontends
38
- if (!window.wu) {
39
- window.wu = {};
40
- }
37
+ // API para que apps notifiquen que están listas (se agrega a window.wu cuando exista)
38
+ // No crear window.wu aquí - eso lo hace index.js con la instancia completa
39
+ this._setupNotifyReady();
40
+ }
41
41
 
42
- // API para que apps notifiquen que están listas
43
- window.wu.notifyReady = (appName) => {
44
- console.log(`[WuRegistry] 📢 App ${appName} called notifyReady()`);
42
+ /**
43
+ * 🔔 Setup notifyReady API cuando window.wu esté disponible
44
+ */
45
+ _setupNotifyReady() {
46
+ const setupFn = () => {
47
+ if (window.wu && !window.wu.notifyReady) {
48
+ window.wu.notifyReady = (appName) => {
49
+ console.log(`[WuRegistry] 📢 App ${appName} called notifyReady()`);
50
+ const event = new CustomEvent('wu:app:ready', {
51
+ detail: { appName, timestamp: Date.now() }
52
+ });
53
+ window.dispatchEvent(event);
54
+ };
55
+ }
56
+ };
45
57
 
46
- const event = new CustomEvent('wu:app:ready', {
47
- detail: { appName, timestamp: Date.now() }
48
- });
58
+ // Intentar setup inmediato
59
+ setupFn();
49
60
 
50
- window.dispatchEvent(event);
51
- };
61
+ // Si window.wu no existe aún, esperar un tick
62
+ if (!window.wu) {
63
+ queueMicrotask(setupFn);
64
+ }
52
65
  }
53
66
 
54
67
  /**
package/src/index.js CHANGED
@@ -75,41 +75,57 @@
75
75
 
76
76
  import { WuCore } from './core/wu-core.js';
77
77
 
78
- // Crear instancia global única de wu-framework
79
- // Por defecto: Health Monitoring activado PERO aging refresh DESACTIVADO
80
- const wu = new WuCore({
81
- healthMonitoring: true, // Detecta containers perdidos
82
- autoHeal: true, // Recupera automáticamente
83
- agingThreshold: Infinity, // NUNCA refresca por edad (era el problema)
84
- healthCheckInterval: 60000 // Chequeo cada 60 segundos
85
- });
86
-
87
- // Hacer wu disponible globalmente para debugging
78
+ // 🔑 SINGLETON PATTERN: Reusar instancia global si existe
79
+ // Esto permite que los microfrontends importen wu-framework y usen la misma instancia del host
80
+ let wu;
81
+
82
+ if (typeof window !== 'undefined' && window.wu && window.wu._isWuFramework) {
83
+ // Ya existe una instancia del host - reutilizarla
84
+ wu = window.wu;
85
+ console.log('🔗 Wu Framework - Reusing existing instance from host');
86
+ } else {
87
+ // Primera carga - crear nueva instancia
88
+ wu = new WuCore({
89
+ healthMonitoring: true,
90
+ autoHeal: true,
91
+ agingThreshold: Infinity,
92
+ healthCheckInterval: 60000
93
+ });
94
+
95
+ // Marcar como instancia de wu-framework
96
+ wu._isWuFramework = true;
97
+ }
98
+
99
+ // Hacer wu disponible globalmente
88
100
  if (typeof window !== 'undefined') {
101
+ // SIEMPRE configurar window.wu con la instancia real (puede haber un objeto vacío)
89
102
  window.wu = wu;
90
103
 
91
- // Agregar información de versión
92
- wu.version = '1.0.1';
93
- wu.info = {
94
- name: 'Wu Framework',
95
- description: 'Universal Microfrontends',
96
- features: [
97
- 'Framework Agnostic',
98
- 'Zero Config',
99
- 'Shadow DOM Isolation',
100
- 'Runtime Loading',
101
- 'Component Sharing'
102
- ]
103
- };
104
+ // Configurar propiedades si no existen
105
+ if (!wu.version) {
106
+ wu.version = '1.0.3';
107
+ console.log('🚀 Wu Framework loaded - Universal Microfrontends ready');
108
+ wu.info = {
109
+ name: 'Wu Framework',
110
+ description: 'Universal Microfrontends',
111
+ features: [
112
+ 'Framework Agnostic',
113
+ 'Zero Config',
114
+ 'Shadow DOM Isolation',
115
+ 'Runtime Loading',
116
+ 'Component Sharing'
117
+ ]
118
+ };
119
+ }
104
120
 
105
121
  // 📡 Exponer Event Bus API globalmente para microfrontends
106
- // Esto permite que los microfrontends usen: window.wu.emit(), window.wu.on(), etc.
107
- wu.emit = (eventName, data, options) => wu.eventBus.emit(eventName, data, options);
108
- wu.on = (eventName, callback) => wu.eventBus.on(eventName, callback);
109
- wu.once = (eventName, callback) => wu.eventBus.once(eventName, callback);
110
- wu.off = (eventName, callback) => wu.eventBus.off(eventName, callback);
111
-
112
- console.log('🚀 Wu Framework loaded - Universal Microfrontends ready');
122
+ // Esto permite: window.wu.emit() Y import { emit } from 'wu-framework'
123
+ if (!wu.emit) {
124
+ wu.emit = (eventName, data, options) => wu.eventBus.emit(eventName, data, options);
125
+ wu.on = (eventName, callback) => wu.eventBus.on(eventName, callback);
126
+ wu.once = (eventName, callback) => wu.eventBus.once(eventName, callback);
127
+ wu.off = (eventName, callback) => wu.eventBus.off(eventName, callback);
128
+ }
113
129
  }
114
130
 
115
131
  // Exportar API principal