Skip to content

Conversation

Satyam
Copy link

@Satyam Satyam commented Dec 12, 2020

useListVals and useObjectVal now accept a transform option to convert values on reading.

Satyam and others added 3 commits December 12, 2020 15:10
`useListVals` and `useObjectVal` now accept a `transform` option
to convert values on reading.
@Satyam
Copy link
Author

Satyam commented Dec 25, 2020

Updated the pull request with the changes merged so far.

This change adds a transform option to useListVals and useObjectVal hook so that the resulting object of list of objects is converted from the representation in the database to that used internally in the application. The option, if not given, does not change the current behaviour.

Since the developer will most likely need to change objects or properties within the object that cannot be represented in a JSON object, such as a date string to a Date object. If such transformation is required, then it is better done already within these hooks, compared to doing it once the values are read since it would:

  • Avoid a new pass through the data while doing the conversion, saving on processing
  • Avoid another memoizing of the results of the conversion, saving on memory
  • Simplify the code for the developer

Additionally both hooks now accept a generic type parameter that allows the returned object or array of objects to be properly typed.

@Satyam
Copy link
Author

Satyam commented Jan 2, 2021

Sorry, I would love to fix the conflicts, but that exceeds my GitHub knowledge.

@chrisbianca
Copy link
Contributor

@Satyam thank you for this and apologies again for the delay in getting it merged. It was easier for me to apply the changes directly onto master rather than try to resolve the conflicts here. I will make sure that you get referenced in the release notes, even if it's not referenced in the commit history.

@chrisbianca
Copy link
Contributor

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