json_serializable_immutable_collections icon indicating copy to clipboard operation
json_serializable_immutable_collections copied to clipboard

Add support for collections in fast_immutable_collections

Open marcglasberg opened this issue 4 years ago • 18 comments

Add support for IList, ISet, IMap, IMapOfSets, ListSet and ListMap classes from https://pub.dev/packages/fast_immutable_collections

marcglasberg avatar Feb 16 '21 22:02 marcglasberg

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

knaeckeKami avatar Feb 20 '21 19:02 knaeckeKami

Yes, it's almost ready.

marcglasberg avatar Feb 21 '21 03:02 marcglasberg

Done: https://pub.dev/packages/fast_immutable_collections/versions/2.0.0-nullsafety.1

marcglasberg avatar Feb 21 '21 18:02 marcglasberg

Great. I'll get to work soon.

knaeckeKami avatar Feb 21 '21 20:02 knaeckeKami

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

knaeckeKami avatar Feb 24 '21 21:02 knaeckeKami

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.

marcglasberg avatar Feb 24 '21 22:02 marcglasberg

great, looking forward to this one as this is the best immutable coll library :)

matejthetree avatar Mar 05 '21 11:03 matejthetree

@matejthetree I already uploaded a version on pub: https://pub.dev/packages/json_serializable_fic

The basic collection types are already supported

knaeckeKami avatar Mar 05 '21 11:03 knaeckeKami

Excellent. How do I use this one together with mobx one you created. How do you go configuring build.yaml?

matejthetree avatar Mar 05 '21 12:03 matejthetree

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.

knaeckeKami avatar Mar 05 '21 12:03 knaeckeKami

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 .

matejthetree avatar Mar 05 '21 14:03 matejthetree

@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?

marcglasberg avatar Mar 05 '21 17:03 marcglasberg

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.

knaeckeKami avatar Mar 05 '21 18:03 knaeckeKami

Added an example project on how to combine multiple packages here: https://github.com/knaeckeKami/json_serializable_immutable_collections/tree/master/combine_example

knaeckeKami avatar Mar 05 '21 19:03 knaeckeKami

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 .

matejthetree avatar Mar 08 '21 14:03 matejthetree

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

knaeckeKami avatar Mar 09 '21 00:03 knaeckeKami

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.

subzero911 avatar Mar 19 '21 08:03 subzero911

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.

knaeckeKami avatar Mar 27 '21 02:03 knaeckeKami