-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Double additions when creating a map #12
Comments
Set the subscription to this.mappedValueComputed after setting of this.previousMappedValue see issue SteveSanderson#12
Thanks for reporting this. I know you've suggested a fix, but I'd love to see the problem at work too. To be sure I've understood the problem properly, would you be able to post a repro? Ideally if you can put a minimal demonstration of the issue on jsFiddle.net, I'll then be able to understand exactly what I missed in the original implementation. |
Hij Steve, It toon me a while tot figure it out. I think it may be a combination with Best regards Evert
|
I can reproduce this issue in my application, but am too having difficulty isolating it into a reproducible jsFiddle. I haven't tested it thoroughly, but evilB's proposed patch also addresses the duplication I'm seeing. I'll continue to try to isolate the issue in a reproducible jsFiddle. |
Here's a jsFiddle that reproduces the issue: http://jsfiddle.net/47Xar/ Note that, just like my application, it relies on the mapping plugin being applied to a (simplified) nested hierarchy. |
Unfortunately, I'm now also seeing issues where sometimes a nested, throttled filter introduces null values into the resulting array where the original had none, independent of evilB's proposed patch above. My application consists of a series of checked items and I currently reproduce this issue after toggling several checkbox states in a row. I suspect the same underlying issue, but if needs be, can try to isolate into another jsFiddle. |
When creating a map in my program, for example:
original array: [1,2] to [1_1,2_2]
I sometimes get the unexpected resulting array [1,1,4,4]. When adding a 3rd element (3) to the original array the resulting array becomes [1,1,4,4,9].
I've managed to track down the issue to the function StateItem
function StateItem(ko, inputItem, initialStateArrayIndex, initialOutputArrayIndex, mapping, arrayOfState, outputObservableArray) {
// ... omitted for brevity
this.mappedValueComputed = ko.computed(this.mappingEvaluator, this);
this.mappedValueComputed.subscribe(this.onMappingResultChanged, this);
this.previousMappedValue = this.mappedValueComputed.peek();
}
In my use case, for whatever reason (i don't remember changing it myself), the computed is not calculated until the first look with peek().
onMappingResultChanged is called when setting previousMappedValue and replaces the element the outputObservableArray with slice(). However, there is nothing in the Array to be removed so the element is just added to the array, which causes the duplicates.
I've resolved the issue by setting the subscription after setting
this.previousMappedValue.
Best Regards,
Evert
The text was updated successfully, but these errors were encountered: