Skip to content

Commit

Permalink
fix: handle setter on binding
Browse files Browse the repository at this point in the history
  • Loading branch information
npenin committed Sep 11, 2024
1 parent 6b72dc1 commit 2dd0a5a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/core/src/observables/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export class BuildSetter<T extends object>
{
const x = getter(target);
if (x)
if (x instanceof ObservableObject)
if (x instanceof Binding)
x.setValue(value);
else if (x instanceof ObservableObject)
x.setValue(member(target), value);
else if (ObservableObject.isWatched(x))
(x[watcher] as ObservableObject<any>).setValue(member(target), value);
Expand Down Expand Up @@ -436,20 +438,25 @@ export class Binding<T> extends EventEmitter<{
let settingValue = false;
target[BindingsProperty][property] = binding;

binding.setValue = function (newValue: T)
{
if (settingValue)
return;
const oldValue = value;
value = newValue;
settingValue = true;
// binding.setValue(newValue)//, binding);
binding.emit('change', { value: newValue, oldValue });
settingValue = false;
}

Object.defineProperty(target, property, {
get()
{
return value;
}, set(newValue: T)
{
if (settingValue)
return;
const oldValue = value;
value = newValue;
settingValue = true;
// binding.setValue(newValue)//, binding);
binding.emit('change', { value: newValue, oldValue });
settingValue = false;
binding.setValue(newValue);
}
});

Expand Down

0 comments on commit 2dd0a5a

Please sign in to comment.