mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(observable-array): reduce no longer ignores zero as initial value (#6402)
* fix(observable-array): reduce no longer ignores zero as initial value * fix(observable-array): reduceRight now functions properly when initial value is not specified or zero
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import * as observable from "../observable";
|
||||
import * as observable from "../observable";
|
||||
import * as observableArrayDef from ".";
|
||||
import * as types from "../../utils/types";
|
||||
|
||||
@ -314,7 +314,7 @@ export class ObservableArray<T> extends observable.Observable implements observa
|
||||
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
|
||||
*/
|
||||
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T {
|
||||
return initialValue ? this._array.reduce(callbackfn, initialValue) : this._array.reduce(callbackfn);
|
||||
return initialValue !== undefined ? this._array.reduce(callbackfn, initialValue) : this._array.reduce(callbackfn);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -323,7 +323,7 @@ export class ObservableArray<T> extends observable.Observable implements observa
|
||||
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
|
||||
*/
|
||||
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T {
|
||||
return this._array.reduceRight(callbackfn, initialValue);
|
||||
return initialValue !== undefined ? this._array.reduceRight(callbackfn, initialValue) : this._array.reduceRight(callbackfn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -331,4 +331,4 @@ export interface ObservableArray<T> {
|
||||
on(eventNames: string, callback: (data: observable.EventData) => void, thisArg?: any);
|
||||
|
||||
on(event: "change", callback: (args: observableArrayDef.ChangedData<T>) => void, thisArg?: any);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user