wu-framework 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +51 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wu-framework",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "🚀 Universal Microfrontends Framework - Framework agnostic, zero config, Shadow DOM isolation",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -75,34 +75,58 @@
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') {
89
- window.wu = wu;
90
-
91
- // Agregar información de versión
92
- wu.version = '1.0.0';
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
-
105
- console.log('🚀 Wu Framework loaded - Universal Microfrontends ready');
101
+ if (!window.wu) {
102
+ window.wu = wu;
103
+ console.log('🚀 Wu Framework loaded - Universal Microfrontends ready');
104
+ }
105
+
106
+ // Siempre configurar estas propiedades (pueden faltar si es instancia reutilizada)
107
+ if (!wu.version) {
108
+ wu.version = '1.0.2';
109
+ wu.info = {
110
+ name: 'Wu Framework',
111
+ description: 'Universal Microfrontends',
112
+ features: [
113
+ 'Framework Agnostic',
114
+ 'Zero Config',
115
+ 'Shadow DOM Isolation',
116
+ 'Runtime Loading',
117
+ 'Component Sharing'
118
+ ]
119
+ };
120
+ }
121
+
122
+ // 📡 Exponer Event Bus API globalmente para microfrontends
123
+ // Esto permite: window.wu.emit() Y import { emit } from 'wu-framework'
124
+ if (!wu.emit) {
125
+ wu.emit = (eventName, data, options) => wu.eventBus.emit(eventName, data, options);
126
+ wu.on = (eventName, callback) => wu.eventBus.on(eventName, callback);
127
+ wu.once = (eventName, callback) => wu.eventBus.once(eventName, callback);
128
+ wu.off = (eventName, callback) => wu.eventBus.off(eventName, callback);
129
+ }
106
130
  }
107
131
 
108
132
  // Exportar API principal