File tree 14 files changed +222
-19
lines changed
14 files changed +222
-19
lines changed Original file line number Diff line number Diff line change 64
64
manager . initialize ( ) ;
65
65
var contentMethods = new ufe . ContentCommunicationHandlerMethods ( ) ;
66
66
contentMethods . dispose = function ( ) { dispose ( ) ; } ;
67
+ contentMethods . handleDataEvent = function ( data ) {
68
+ console . log ( 'Iframe recevied data: \n\n' + JSON . stringify ( data ) ) ;
69
+ } ;
67
70
communicationHandler = new ufe . CrossWindowContentCommunicationHandler (
68
71
manager ,
69
72
contentMethods
104
107
} else {
105
108
if ( communicationHandler ) {
106
109
communicationHandler . dispatchBeforeUpdate ( ) ;
110
+
107
111
setTimeout ( ( ) => {
108
112
communicationHandler . dispatchUpdated ( ) ;
109
113
} , 1000 ) ;
123
127
// Simulate a delay to consider exts processing
124
128
window . setTimeout ( ( ) => {
125
129
communicationHandler . dispatchMounted ( ) ;
130
+ communicationHandler . sendData ( [ 'Data from content!' ] ) ;
126
131
} , 1000 ) ;
127
132
}
128
133
}
Original file line number Diff line number Diff line change 28
28
case 'error' :
29
29
console . error ( evt . error ) ;
30
30
break ;
31
- default :
31
+ case 'data' :
32
+ console . log ( 'Data from child:\n' + JSON . stringify ( evt . data ) ) ;
33
+ break ;
34
+ default :
32
35
alert ( 'Unknown event: ' + evt . type ) ;
33
36
}
34
37
}
43
46
globalHandlers [ 'beforeDestroy' ] = mfeEventHadler ;
44
47
globalHandlers [ 'destroyed' ] = mfeEventHadler ;
45
48
globalHandlers [ 'error' ] = mfeEventHadler ;
49
+ globalHandlers [ 'data' ] = mfeEventHadler ;
46
50
47
51
48
52
var configuration = new ufe . RootComponentOptions ( ) ;
206
210
if ( ! navbarIframeId )
207
211
return ;
208
212
213
+ mfe . getChild ( navbarIframeId ) . sendData ( {
214
+ 'foo' : 'bar'
215
+ } )
216
+
209
217
await mfe . removeChild ( navbarIframeId ) ;
210
218
navbarIframeId = '' ;
211
219
}
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ export abstract class ChildComponent extends Component {
42
42
methods . mounted = ( ) => this . callHandler ( ComponentEventType . Mounted ) ;
43
43
methods . beforeUpdate = ( ) => this . callHandler ( ComponentEventType . BeforeUpdate ) ;
44
44
methods . updated = ( ) => this . callHandler ( ComponentEventType . Updated ) ;
45
+ methods . data = ( data : any ) => this . callHandler ( ComponentEventType . Data , data ) ;
45
46
methods . beforeDispose = ( ) => this . contentBeginDisposed ( ) ;
46
47
methods . disposed = ( ) => this . contentDisposed ( ) ;
47
48
return this . getCommunicationHandlerCore ( methods ) ;
@@ -139,4 +140,12 @@ export abstract class ChildComponent extends Component {
139
140
this . contentDisposePromise = null ;
140
141
await super . disposeCore ( ) ;
141
142
}
143
+
144
+ /**
145
+ * Send data.
146
+ * @param data The data to send.
147
+ */
148
+ public sendData ( data : any ) : void {
149
+ this . communicationHandler ?. sendData ( data ) ;
150
+ }
142
151
}
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ export class ContainerCommunicationHandlerMethods {
26
26
* Call the container to signal the component has disposed(almost).
27
27
*/
28
28
public [ CommunicationsEventKind . Disposed ] : ( ) => void = noop ;
29
+ /**
30
+ * Call the container to signal the component has disposed(almost).
31
+ */
32
+ public [ CommunicationsEventKind . Data ] : ( data : any ) => void = noop ;
29
33
}
30
34
31
35
/**
@@ -65,7 +69,7 @@ export abstract class ContainerCommunicationHandler {
65
69
if ( ! method )
66
70
return ;
67
71
68
- method ( ) ;
72
+ method ( e . data ) ;
69
73
}
70
74
71
75
/**
@@ -97,6 +101,16 @@ export abstract class ContainerCommunicationHandler {
97
101
this . communicationsManager ?. send ( event ) ;
98
102
}
99
103
104
+ /**
105
+ * Send data.
106
+ * @param data The data to send.
107
+ */
108
+ public sendData ( data : any ) : void {
109
+ const event = new CommunicationsEvent ( CommunicationsEventKind . Data ) ;
110
+ event . data = data ;
111
+ this . communicationsManager ?. send ( event ) ;
112
+ }
113
+
100
114
/**
101
115
* Reuest that the content begins disposing.
102
116
*/
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ export class ContentCommunicationHandlerMethods {
10
10
* Method to dispose the content.
11
11
*/
12
12
public dispose : ( ) => void = noop ;
13
+ /**
14
+ * Method to dispose the content.
15
+ */
16
+ public handleDataEvent : ( data : any ) => void = noop ;
13
17
}
14
18
15
19
/**
@@ -49,6 +53,11 @@ export abstract class ContentCommunicationHandler {
49
53
this . methods . dispose ( ) ;
50
54
}
51
55
break ;
56
+ case CommunicationsEventKind . Data :
57
+ if ( this . methods ) {
58
+ this . methods . handleDataEvent ( e . data ) ;
59
+ }
60
+ break ;
52
61
default :
53
62
throw new Error ( `The "${ e . kind } " event is not configured.` ) ;
54
63
}
@@ -76,6 +85,15 @@ export abstract class ContentCommunicationHandler {
76
85
this . communicationsManager ?. send ( event ) ;
77
86
}
78
87
88
+ /**
89
+ * Dispatch event to signal mounting finished.
90
+ */
91
+ public sendData ( data : any ) : void {
92
+ const evt = new CommunicationsEvent ( CommunicationsEventKind . Data ) ;
93
+ evt . data = data ;
94
+ this . send ( evt ) ;
95
+ }
96
+
79
97
/**
80
98
* Dispatch event to signal mounting finished.
81
99
*/
Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ export enum CommunicationsEventKind {
7
7
BeforeUpdate = 'beforeUpdate' ,
8
8
Updated = 'updated' ,
9
9
BeforeDispose = 'beforeDispose' ,
10
- Disposed = 'disposed'
10
+ Disposed = 'disposed' ,
11
+ Data = 'data'
11
12
}
12
13
13
14
/**
Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ export abstract class Component {
160
160
* Call a specific event handler.
161
161
* @param type The type of handler to call.
162
162
*/
163
- protected callHandler ( type : ComponentEventType ) : void {
163
+ protected callHandler ( type : ComponentEventType , data ?: any ) : void {
164
164
if ( type === ComponentEventType . Error )
165
165
throw new Error ( `For calling the "${ ComponentEventType . Error } " handler use the "callErrorHandler" method.` ) ;
166
166
@@ -170,13 +170,15 @@ export abstract class Component {
170
170
171
171
if ( handler ) {
172
172
try {
173
- handler ( new ComponentEvent (
173
+ const event = new ComponentEvent (
174
174
this . id ,
175
175
type ,
176
176
this . rootElement ,
177
177
this . getParentElement ( ) ,
178
178
null
179
- ) ) ;
179
+ ) ;
180
+ event . data = data ;
181
+ handler ( event ) ;
180
182
} catch ( error ) {
181
183
this . callErrorHandler ( error ) ;
182
184
}
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ export enum ComponentEventType {
10
10
Updated = 'updated' ,
11
11
BeforeDestroy = 'beforeDestroy' ,
12
12
Destroyed = 'destroyed' ,
13
- Error = 'error'
13
+ Error = 'error' ,
14
+ Data = 'data'
14
15
}
15
16
16
17
/**
@@ -28,6 +29,7 @@ export class ComponentEvent {
28
29
public parentEl : HTMLElement ;
29
30
public error : Error | null ;
30
31
public timestamp : Date ;
32
+ public data : any ;
31
33
32
34
/**
33
35
* COnstructor.
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export class ComponentEventHandlers {
14
14
[ ComponentEventType . BeforeDestroy ] ?: ComponentEventHandler ;
15
15
[ ComponentEventType . Destroyed ] ?: ComponentEventHandler ;
16
16
[ ComponentEventType . Error ] ?: ComponentEventHandler ;
17
+ [ ComponentEventType . Data ] ?: ComponentEventHandler ;
17
18
}
18
19
19
20
/**
You can’t perform that action at this time.
0 commit comments