Closed jordan-ware closed 5 years ago
I'll have to do some more tests before merging this one, the last commit I made had something similar here and it got removed. I have to see if it was causing the infinite loop or if it was just an omission. I remember that I see more problem when I use the date picker inside a modal window component, I'll have to test against it
Oops, hit a wrong button sorry. I was going to say I've dealt with this issue before and realized I have my own wrapper code that deals with these syncing issues and exits as early as possible.
In the below example I'm syncing a date
with a moment
in my wrapper, slight changes can be made to handle the formatted string instead:
dateValueChanged(newValue?: Date, oldValue?: Date) {
//exits early because no actual change is detected
if (newValue && oldValue && newValue.getTime() == oldValue.getTime()) {
return;
} else if (!newValue && !oldValue) {
return;
}
//sync value logic below - only assign new value if it's different
if (newValue) {
if (this.value && this.value.valueOf() == newValue.getTime()) {
return;
}
this.value = moment(newValue);
} else {
//this could probably be avoided too
this.value = null;
}
}
*edit, apologies, it's in typescript
I'll adapt this to the model/value sync if you like, cause I noticed there's still some unnecessary cycles still happening in the current implementation
Finally tried it, it seems to be ok with the tests I've done.
Binding a
model
but novalue
resulted in thevalue
being initialised with a moment object instead of the expected formatted string, resulting in nothing appearing in the text box despite the date correctly bound behind the scenes. This change fixes this issue.