@@ -56,6 +56,26 @@ struct WindowCreatedEvent {
5656 label : String ,
5757}
5858
59+ pub ( crate ) struct WindowEmitArgs {
60+ pub event : String ,
61+ pub source_window_label : String ,
62+ pub payload : String ,
63+ }
64+
65+ impl WindowEmitArgs {
66+ pub fn from < S : Serialize > (
67+ event : & str ,
68+ source_window_label : Option < & str > ,
69+ payload : S ,
70+ ) -> crate :: Result < Self > {
71+ Ok ( WindowEmitArgs {
72+ event : serde_json:: to_string ( event) ?,
73+ source_window_label : serde_json:: to_string ( & source_window_label) ?,
74+ payload : serde_json:: to_string ( & payload) ?,
75+ } )
76+ }
77+ }
78+
5979/// Monitor descriptor.
6080#[ derive( Debug , Clone , Serialize ) ]
6181#[ serde( rename_all = "camelCase" ) ]
@@ -1764,18 +1784,13 @@ impl<R: Runtime> Window<R> {
17641784 self . emit ( event, payload)
17651785 }
17661786
1767- pub ( crate ) fn emit_internal < S : Serialize > (
1768- & self ,
1769- event : & str ,
1770- source_window_label : Option < & str > ,
1771- payload : S ,
1772- ) -> crate :: Result < ( ) > {
1787+ pub ( crate ) fn emit_internal ( & self , emit_args : & WindowEmitArgs ) -> crate :: Result < ( ) > {
17731788 self . eval ( & format ! (
17741789 "(function () {{ const fn = window['{}']; fn && fn({{event: {}, windowLabel: {}, payload: {}}}) }})()" ,
17751790 self . manager. event_emit_function_name( ) ,
1776- serde_json :: to_string ( event) ? ,
1777- serde_json :: to_string ( & source_window_label) ? ,
1778- serde_json :: to_value ( payload) ? ,
1791+ emit_args . event,
1792+ emit_args . source_window_label,
1793+ emit_args . payload
17791794 ) ) ?;
17801795 Ok ( ( ) )
17811796 }
0 commit comments