Browse Source

Expose Event Name to TS so that it can be used inside unsubscribeFromEvent calls

Shaddock Heath 9 năm trước cách đây
mục cha
commit
f23da29636

+ 4 - 1
Source/ToolCore/JSBind/JSBTypeScript.cpp

@@ -450,9 +450,12 @@ void JSBTypeScript::ExportModuleEvents(JSBModule* module)
 
         source += "    }\n\n";
 
+        // Write the event name
+        source += ToString("    export var %sName : string;\n", scriptEventName.CString());
         // Write the event function signature
+        source += ToString("    export function %s (callback : Atomic.EventCallback<%s>) : Atomic.EventMetaData;\n\n", scriptEventName.CString(), scriptEventName.CString());
 
-        source += ToString("\n    export function %s (callback : Atomic.EventCallback<%s>) : Atomic.EventMetaData;\n\n", scriptEventName.CString(), scriptEventName.CString());
+        source += "\n\n";
 
     }
     source_ += source;

+ 3 - 0
Source/ToolCore/JSBind/JavaScript/JSModuleWriter.cpp

@@ -274,6 +274,9 @@ void JSModuleWriter::WriteModulePreInit(String& source)
 
     for (unsigned i = 0; i < events.Size(); i++)
     {
+        source.AppendWithFormat("duk_push_string(ctx, \"%s\");\n", events[i]->GetEventName().CString());
+        source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%sName\");\n", events[i]->GetScriptEventName(BINDINGLANGUAGE_JAVASCRIPT).CString());
+
         source.AppendWithFormat("js_define_native_event(ctx, \"%s\", \"%s\");\n", events[i]->GetEventName().CString(), events[i]->GetScriptEventName(BINDINGLANGUAGE_JAVASCRIPT).CString());
     }