Skip to content

Commit

Permalink
Merge pull request #402 from near/use_custom_deserializer_if_specified
Browse files Browse the repository at this point in the history
Use deserializer from options if specified within getValueWithOptions function
  • Loading branch information
ailisp authored Jul 23, 2024
2 parents e09aa61 + 390e656 commit da9c8b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions packages/near-sdk-js/lib/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/near-sdk-js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ export type Mutable<T> = { -readonly [P in keyof T]: T[P] };
export function getValueWithOptions<DataType>(
subDatatype: unknown,
value: Uint8Array | null,
options: Omit<GetOptions<DataType>, "serializer"> = {
deserializer: deserialize,
}
options: Omit<GetOptions<DataType>, "serializer"> = {}
): DataType | null {
if (value === null) {
return options?.defaultValue ?? null;
}

const deserializer = options.deserializer || deserialize;

// here is an obj
let deserialized = deserialize(value);
let deserialized = deserializer(value);

if (deserialized === undefined || deserialized === null) {
return options?.defaultValue ?? null;
Expand Down

0 comments on commit da9c8b8

Please sign in to comment.