mobxjs / serializr

Serialize and deserialize complex object graphs to and from JSON and Javascript classes
MIT License
766 stars 52 forks source link

Publish 2.0.0 to npm #125

Closed NaridaL closed 4 years ago

NaridaL commented 4 years ago

@mweststrate

mweststrate commented 4 years ago

Hey @NaridaL, just glanced through your recent PRs, and looks like you are doing some really solid work here! Awesome👏

If you are interested, I can give you publish rights on this package if you can share your npm user name. That means I won't be your bottleneck any longer ;-)

NaridaL commented 4 years ago

Works for me: https://www.npmjs.com/~narida

mweststrate commented 4 years ago

Done!

On Mon, Feb 10, 2020 at 10:02 AM Adrian Leonhard notifications@github.com wrote:

Works for me: https://www.npmjs.com/~narida

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/mobxjs/serializr/issues/125?email_source=notifications&email_token=AAN4NBERPRAPVUMLWEEXOHTRCEQ4HA5CNFSM4KR2ZSP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELH5CQY#issuecomment-584044867, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBEPQUBV4GKJTZOJSRTRCEQ4HANCNFSM4KR2ZSPQ .

NaridaL commented 4 years ago

I've published 2.0.0-beta under @beta in case anyone else wants to test it too. Will publish 2.0.0 in a couple of days.

mweststrate commented 4 years ago

https://twitter.com/mweststrate/status/1226958538297290753

danfma commented 4 years ago

Good work, @NaridaL!

I'm using it on a project. I will do some tests today or tomorrow and then I give you feedback about it.

danfma commented 4 years ago

Hey, @NaridaL!

It looks good until now.

But, before publishing, what do you think about exposing the context during the custom serialization in the serializer? With that, we could create a custom rule named embedded that will merge the properties of a composed child, directly in the parent serialization.

We could use this version increment to add that.

An example of that:

class Name {
  @serializable(primitive())
  firstName = '';

  @serializable(primitive())
  lastName = '';
}

class Person {
  @serializable(embedded(Name))
  name = new Name();
}

So, a Person's instance could be serialized like:

{
  "firstName": "name",
  "lastName": "surname"
}

Possible rule example:

export function embedded<TModel>(type: Type<TModel>): PropSchema {
  return custom(
    (data, context) => {
        Object.assign(context.json, serialize(data));
        return SKIP;
    },
    (_, context) => deserialize(type, context.json)
  );
}
NaridaL commented 4 years ago

@danfma There is currently no serialization context. However the afterDeserialize and beforeDeserialize callbacks get passed a "parentJson" object, maybe we could do the same for the serialization callback.

danfma commented 4 years ago

Yes, I know that we have a context for the deserialization, so I thought we could have the same for the serialization (sorry, I didn't read the code).

But, if we have a {before/after}Serialization we could reach that too.

NaridaL commented 4 years ago

I've published 2.0.0. Closing this issue. @danfma Adding another parameter to the serialization function should be possible; you should open another issue or PR if you want to look into it further.