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

serializing bigint #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

robmanganelly
Copy link

Content of this PR:

  • 2 Functions that wrap JSON.stringify and JSON.parse to include serialization and rehydration of bigint values.
  • Unit test code modifications to include values of type bigint on test cases.

Considerations.

  • I applied the functions in place for the sake of brevity, but next iterations could move them into utility space and get them their own unit test.
  • There is a commented test case, see line 137 that has failing test case, which i did not fix, as it is a different issue, unrelated to this PR.

@rainerhahnekamp rainerhahnekamp self-requested a review April 14, 2024 16:24
Copy link
Collaborator

@rainerhahnekamp rainerhahnekamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work @robmanganelly. I've left some comments.

@@ -1,14 +1,16 @@
import { getState, patchState, signalStore, withState } from '@ngrx/signals';
import { withStorageSync } from './with-storage-sync';
import { withBigIntRehydration, withBigIntReplacement, withStorageSync } from './with-storage-sync';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to rename withBigIntRehydration and withBigIntReplacement to serialize and deserialize. I think bigint will not be the last type where we require custom code.

import { TestBed } from '@angular/core/testing';

interface StateObject {
foo: string;
age: number;
big: bigint;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible, that we leave the tests as they are and just create a separate test which checks the de/serialization for bigint?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the package-lock.json should be changed, right?

@@ -58,15 +104,20 @@ export type SyncConfig<State> = {
/**
* Function used to parse the state coming from storage.
*
* `JSON.parse()` by default
* ~~`JSON.parse()` by default~~
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can replace that with parse and stringify (below).

@robmanganelly
Copy link
Author

robmanganelly commented Apr 25, 2024 via email

@rainerhahnekamp
Copy link
Collaborator

@robmanganelly if you don't have the time, no worries. We'll merge and I can do the changes myself. Just let me know, cheers!

@robmanganelly
Copy link
Author

robmanganelly commented Apr 25, 2024 via email

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

Successfully merging this pull request may close these issues.

2 participants