Closed baparham closed 2 years ago
CC @armantorkzaban
I am currently working on this one.
@armantorkzaban
We have to make a technical decision about the types of the reducer functions. I thought of two ways to handle it.
dynamic
types:
The previousValue will be initialized if initialValue==null with currentProperties, currentGeometry, a.s.o., like in the original JS version and also like in Arman’s and Brad’s initial versions. We will drop the generic types to not limit it to geodata-related data types.
generic types: Very clean, but we break a little bit with Turf.js-compatibility: We don’t have the if-clause to initialize previousValue if initialValue==null. I’ve implemented that in the latest commit to this branch.
You can see in the diff of the latest commit clearly the two concepts 1 & 2
Let’s decide together!
We now decided for a different approach, where we don't lose any type information and are entirely compatible with TurfJS! But in this version, we added another type check to the functions:
if (previousValue == null && featureIndex == 0 && currentGeometry is T) {
previousValue = currentGeometry?.clone() as T;
} else {
@armantorkzaban For the unit tests, please look at geomReduce, Brad did a great job there. I added some lines to test the behavior with dynamic
types.
TurfJS may also have some good inspiration for the tests..