json_serializable_immutable_collections
json_serializable_immutable_collections copied to clipboard
Add support for collections in fast_immutable_collections
Add support for IList
, ISet
, IMap
, IMapOfSets
, ListSet
and ListMap
classes from https://pub.dev/packages/fast_immutable_collections
Do you plan on migrating to null safety soon? I already migrated this package and it would be easier if fast_immutable_collections also was nullsafe
Yes, it's almost ready.
Done: https://pub.dev/packages/fast_immutable_collections/versions/2.0.0-nullsafety.1
Great. I'll get to work soon.
a first version is available: https://pub.dev/packages/json_serializable_fic
It supports IList, IMap and ISet for the moment, I think these are most needed types. I'll add the other types later if there's demand.
@marcglasberg I would love feedback if you think that the generated code is correct. I have a test model file here, that should use most features https://github.com/knaeckeKami/json_serializable_immutable_collections/blob/master/json_serializable_fic/test/integration/model.dart and a generated file here: https://github.com/knaeckeKami/json_serializable_immutable_collections/blob/master/json_serializable_fic/test/integration/model.g.dart
Seems right, at first glance.
The one thing you shouldn't be doing is generating collections and then turning them into immutable ones. You should create them immutable from the Iterable
directly, so that it doesn't do unnecessary defensive copies. And you are indeed creating them from the Iterable
directly by doing iterable.toIList()
. So it seems ok to me.
great, looking forward to this one as this is the best immutable coll library :)
@matejthetree I already uploaded a version on pub: https://pub.dev/packages/json_serializable_fic
The basic collection types are already supported
Excellent. How do I use this one together with mobx one you created. How do you go configuring build.yaml?
Yeah, this is unfortunately not that easy.
I didn't want to put support mobx, built_collection, kt_dart and fast_immutable_collections in the same package, because it would bloat the dependencies of users that only need one of those and could lead to unnecessary dependency conflicts. So I split it up.
The drawback is that now it's harder for users who want the support of multiple of these packages.
You would have to depend on both packages, but exclude their builders form build.yaml (like you exclude json_serializable:
json_serializable:json_serializable:
options:
explicit_to_json: true
generate_for:
include:
exclude:
- test/**
- lib/**
- example/**
and then add your own builder where you add all the type helpers from the package
(see for example the type helpers of mobx: https://github.com/knaeckeKami/json_serializable_immutable_collections/blob/master/json_serializable_mobx/lib/builder.dart#L33) and add this builder to build.yaml (see https://github.com/knaeckeKami/json_serializable_immutable_collections/blob/master/json_serializable_mobx/build.yaml#L23) for example.
I will add documentation and an example how to do this later.
thx, ill do it later as well.
On Fri, Mar 5, 2021 at 1:53 PM knaeckeKami [email protected] wrote:
Yeah, this is unfortunately not that easy.
I didn't want to put support mobx, built_collection, kt_dart and fast_immutable_collections in the same package, because it would bloat the dependencies of users that only need one of those and could lead to unnecessary dependency conflicts. So I split it up.
The drawback is that now it's harder for users who want the support of multiple of these packages.
You would have to depend on both packages, but exclude their builders form build.yaml (like you exclude json_serializable:
json_serializable:json_serializable: options: explicit_to_json: true generate_for: include: exclude: - test/** - lib/** - example/**
and then add your own builder where you add all the type helpers from the package
(see for example the type helpers of mobx: https://github.com/knaeckeKami/json_serializable_immutable_collections/blob/master/json_serializable_mobx/lib/builder.dart#L33 ) and add this builder to build.yaml (see https://github.com/knaeckeKami/json_serializable_immutable_collections/blob/master/json_serializable_mobx/lib/builder.dart#L33 ) for example.
I will add documentation and an example how to do this later.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/knaeckeKami/json_serializable_immutable_collections/issues/14#issuecomment-791400851, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACMX5IULATSN2GMAAMXXOH3TCDH5HANCNFSM4XXJC4AQ .
@knaeckeKami Won't Dart tree shake remove the unused classes anyway? So that it won't bloat the dependencies of users, at least in the compiled result?
You're right, the tree shaker would get rid of the unused code, but I'm still worried because it could lead to dependency conflicts. I also got issues like this: https://github.com/knaeckeKami/json_serializable_immutable_collections/issues/11 so some people like having a minimal set of dependencies. Also, if I add support to getx one day (as requested here: https://github.com/knaeckeKami/json_serializable_immutable_collections/issues/15 ), then I would add a dependency for flutter, and the package would break for users that use vanilla dart.
There's no perfect solution there. But I will add an example project on how to combine the TypeHelpers and a builder that combines support for multiple/all implemented types.
Added an example project on how to combine multiple packages here: https://github.com/knaeckeKami/json_serializable_immutable_collections/tree/master/combine_example
thx
On Fri, Mar 5, 2021 at 8:05 PM knaeckeKami [email protected] wrote:
Added an example project on how to combine multiple packages here: https://github.com/knaeckeKami/json_serializable_immutable_collections/tree/master/combine_example
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/knaeckeKami/json_serializable_immutable_collections/issues/14#issuecomment-791620728, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACMX5IR63UXMKUY5OPU5ZA3TCETRNANCNFSM4XXJC4AQ .
just thought of something: I could publish a json_serializable_all (name tdb) package that supports all types in addition to the specialized packages.
this would not be much work for me and save users who want e.g. mobx and fix some time
just thought of something: I could publish a json_serializable_all (name tdb) package that supports all types in addition to the specialized packages.
this would not be much work for me and save users who want e.g. mobx and fix some time
That would be nice. Just thought about the situation when I rewrite my old project from MobX to GetX, and have to have both generators (for Observables and for Rx types) in the same project.
I did a major revamp of this set of packages.
I split up the packages in TypeHelpers
, and builders.
TypeHelpers are just classes that are used by json_serializable that add support by new types.
But they don't do anything on their own.
One needs to configure a builder and register TypeHelpers with that builder. This is done in the builder packages.
I also refactored the existing TypeHelpers and removed duplicated code. This should make it much easier to add support for new packages in the Future.
For users of these packages, nothing should change, but it's possible that introduced regressions are not caught by the tests.