Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions haxe/ui/locale/LocaleManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -137,6 +155,7 @@ class LocaleManager {
}


isRefreshing = true;
for (prop in propMap.keys()) {
var entry = propMap.get(prop);
if (entry.callback != null) {
Expand All @@ -147,6 +166,7 @@ class LocaleManager {
Reflect.setProperty(component, prop, value);
}
}
isRefreshing = false;
}

public function refreshAll() {
Expand Down
5 changes: 4 additions & 1 deletion haxe/ui/macros/Macros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down