Add safeMap utility (or something like it) #2109
Labels
brainstorming/wild idea
Brainstorming / Wild idea
docs or examples
Documentation or examples related
enhancement
Possible enhancement
hacktoberfest
level: easy
If you have something like:
And you load all your
Drawers
before loadingDocuments
, and you can't guarantee thatdrawer.documents
will end up referring to valid IDs, you'll end up with an error when if you calldrawer.documents.map
, because we're invoking the reference.It would be awesome to be able to safely iterate the array in some way with a helper function. Something like this:
(This implementation may crash right now, I'm not exactly sure how to get it to work).
Would be nice to offer it as a utility on
types.array
, and similarly ontypes.map
for things.This came from a real-world problem using MST to load data from an API where document IDs couldn't be guaranteed to be valid by the time they get loaded.
I don't love expanding the API surface of our already-large API, but this could be helpful. At the very least, maybe we offer a code snippet in the docs to help folks in this scenario.
Happy to see some reproductions, demos, PRs, etc.
The text was updated successfully, but these errors were encountered: