Closed NaridaL closed 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 ;-)
Works for me: https://www.npmjs.com/~narida
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 .
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.
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.
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)
);
}
@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.
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.
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.
@mweststrate