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 +1 -1
- package/src/core/wu-registry.js +25 -12
- package/src/index.js +46 -30
package/package.json
CHANGED
package/src/core/wu-registry.js
CHANGED
|
@@ -34,21 +34,34 @@ export class WuRegistry {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
58
|
+
// Intentar setup inmediato
|
|
59
|
+
setupFn();
|
|
49
60
|
|
|
50
|
-
|
|
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
|
-
//
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
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
|
-
//
|
|
92
|
-
wu.version
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
'
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|