diff --git a/haxe/ui/locale/LocaleManager.hx b/haxe/ui/locale/LocaleManager.hx index dec3f5e6e..76c34691e 100644 --- a/haxe/ui/locale/LocaleManager.hx +++ b/haxe/ui/locale/LocaleManager.hx @@ -84,6 +84,24 @@ class LocaleManager { public function unregisterComponent(component:Component) { _registeredComponents.remove(component); } + + public function unregisterProperty(component:Component, prop:String) { + var propMap = _registeredComponents.get(component); + if (propMap == null) { + return; + } + propMap.remove(prop); + } + + /* + Guards the Reflect.setProperty calls in refreshFor below: those re-invoke the same + generated property setter that calls unregisterProperty above for any non-{{}} value, since + by the time refreshFor resolves a binding to a plain string, that string no longer contains + "{{"/"}}" either. Without this guard, applying a freshly-registered binding for the first + time would immediately unregister the very entry refreshFor just used, silently turning every + binding into a one-shot that never updates again on a later locale change. + */ + public var isRefreshing(default, null):Bool = false; public function findBindingExpr(component:Component, prop:String):String { var propMap = _registeredComponents.get(component); @@ -137,6 +155,7 @@ class LocaleManager { } + isRefreshing = true; for (prop in propMap.keys()) { var entry = propMap.get(prop); if (entry.callback != null) { @@ -147,6 +166,7 @@ class LocaleManager { Reflect.setProperty(component, prop, value); } } + isRefreshing = false; } public function refreshAll() { diff --git a/haxe/ui/macros/Macros.hx b/haxe/ui/macros/Macros.hx index fb785fa60..c12a8348d 100644 --- a/haxe/ui/macros/Macros.hx +++ b/haxe/ui/macros/Macros.hx @@ -676,7 +676,10 @@ class Macros { haxe.ui.locale.LocaleManager.instance.registerComponent(cast this, $v{f.name}, value); return value; } - case _: + case _: + } + if (haxe.ui.locale.LocaleManager.instance.isRefreshing == false) { + haxe.ui.locale.LocaleManager.instance.unregisterProperty(cast this, $v{f.name}); } if (behaviours == null) { behaviours = new haxe.ui.behaviours.Behaviours(cast this);