Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: On deserialization it would be nice if the meta, links, etc, are available as a Symbol in the data #211

Open
diosney opened this issue Sep 25, 2019 · 0 comments

Comments

@diosney
Copy link

diosney commented Sep 25, 2019

Right now after deserialization, we don't have access to the meta data like meta, links and so on, only to the data itself.

This has a caveat, that if we pass or return that data to another method, we lose access to that meta data and forces us now to destructure it before deserialization to pass it as an extra param.

This could be easily solved if that meta data is returned as a non enumerable, non writable, non configurable property keyed with a Symbol, to avoid clashes, so we can have access to it at any time if we have a reference to the deserialized data itself.

For instance:

let deserializedData: any = new JsonApiSerializer
          .Deserializer(JSON_DESERIALIZER_DEFAULT_OPTIONS)
          .deserialize(jsonApiResponse);

console.log(deserializedData[JsonApiSerializer.EXTRAS_SYMBOL]); 

// Example output could be:
{
   extras: {
     links: {...},
     meta: {...}
   }
}

// Extras Symbol could be something like:
JsonApiSerializer.EXTRAS_SYMBOL = new Symbol('json-api-serializer-extras-symbol');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant