-
Notifications
You must be signed in to change notification settings - Fork 35
Null-safety implementation #25
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Capturing from the spec:
To me optional equals nullable. The issue with defaulting to 0 means you can't differentiate when a value is uninitialized or actually 0.
My personal opinion would be to make these non-nullable. Is their any language in the specification that goes against this? Conceptually a GeoJSON type is determined by the underlying geometry, if their isn't any geometry, is it really an instance of it?
👍 |
And for Features [I wanted to treat Feature, FeatureCollection, GeometryCollection and the geometry types (Point, Polygon, ...) the same way nullability-wise]:
|
Totally makes sense, but I have to see how that will complicate the implementation of bounding boxes. Following the RFC, they can have either 4 (without altitude, 2D) or 6 parameters (with alt, 3D), see here. I had implemented it before as 3D by default. turf_dart/lib/src/geojson.dart Line 211 in 14e9b66
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few thoughts
I think I now have implemented everything necessary for the migration |
@@ -6,155 +6,126 @@ part of 'geojson.dart'; | |||
// JsonSerializableGenerator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who or what changes this file? Is it generated code somehow or is it used to generate code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It‘s auto-generated by json_serializable.
This package: https://pub.dev/packages/json_serializable
A code generator for JSON (de)serialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you've addressed our questions and decisions, nice work!
History is reversible. At least here it is 😂 |
Hi,
this is my attempt at null-safety.
GeoJson serialization/deserialization
I tried to follow the official GeoJSON RFC-standard as good as possible, there is still some ambiguity left on how to interpret and translate it into Dart.
The attributes of
CoordinateType
and it's child-classesBBox
andPosition
are non-nullable.turf_dart/lib/src/geojson.dart
Line 35 in 315b05f
RFC 7946 – 3.1.1 The optional third attribute (
alt
) forPosition
is also non-nullable and by default == 0. I'm not sure if this is a good way of dealing with it?!RFC 7946 – 3.1.2 and following: I made the
coordinates
attribute forPoint
,MultiPoint
,LineString
,MultiLineString
,Polygon
andMultiPolygon
nullable. But I only made the "top-level" type nullable: this means, either you assignnull
tocoordinates
or you have to provide it entirely null-safe.But should it be nullable? Let's vote on that.
RFC 7946 – 3.1.8 similarly to the other types above, I made the
geometries
attribute forGeometryCollection
nullableRFC 7946 – 3.2
Feature
: thegeometry
is also nullableRFC 7946 – 3.3
FeatureCollection
: thefeatures
attribute "can be empty" according to the RFC-standard, so I chose to treat it as nullable.Ported "Components" from Turf.js
For functions such as
midpoint
,destination
, etc. we have two implementations: "raw" (which takes just thePosition
) and the other one withPoint
s, which just passesPoint.position
attribute to the "raw" function.turf_dart/lib/src/midpoint.dart
Line 14 in 315b05f
turf_dart/lib/src/midpoint.dart
Line 6 in 315b05f
I don't really think using the bang(!)-operator is a good way of dealing with it, because we give the responsibility to check for
null
again to the user, which is kind of opposed to the whole idea of null-safety.turf_dart/lib/src/midpoint.dart
Line 15 in 315b05f
Please @baparham @tobrun, review and correct the migration for the meta functions, ...
Also: I have still an error with json_serializable, which has some kind of type error, I guess it has something to do with the nested-generic types..
When I try to run:
dart run build_runner build
, this is the output:... [SEVERE] json_serializable:json_serializable on lib/src/geojson.dart: UnimplementedError: (TypeParameterTypeImpl) T? [INFO] Running build completed, took 3.8s [INFO] Caching finalized dependency graph completed, took 36ms [SEVERE] Failed after 3.8s
@tobrun @baparham if you could take a look and help me with all of the decisions? 🙂