From ae3cb5c0431928e8f0ebd36fdc96a5a4961aeb63 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Fri, 27 May 2022 12:38:12 -0700 Subject: [PATCH] MessageDispatcher: fix Callback class not working properly on OpenFL's flash/air targets On those targetts, no exceptions are thrown until the function is called, but that's too late because the length was already incorrectly detected as 0 --- .../framework/impl/MessageDispatcher.hx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/robotlegs/bender/framework/impl/MessageDispatcher.hx b/src/robotlegs/bender/framework/impl/MessageDispatcher.hx index fe295d6..f81afe6 100644 --- a/src/robotlegs/bender/framework/impl/MessageDispatcher.hx +++ b/src/robotlegs/bender/framework/impl/MessageDispatcher.hx @@ -178,6 +178,26 @@ class Callback { public var length:Int = 0; public function new(value:Dynamic) { + #if flash + length = Reflect.field(value, "length"); + call = (v1:Dynamic, v2:Dynamic) -> { + if (length == 0) { + var func0:Void->Void = value; + func0(); + } + else if (length == 1) { + var func1:Dynamic->Void = value; + func1(v1); + } + else if (length == 2) { + var func2:Dynamic->Dynamic->Void = value; + func2(v1, v2); + } + else { + throw "Bad handler signature"; + } + } + #else var func0:Void->Void = null; try { func0 = value; @@ -207,5 +227,6 @@ class Callback { } } } + #end } }