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

Update Dictionary#set signature to take two arguments: key and value #4286

Closed
kraenhansen opened this issue Feb 1, 2022 · 2 comments
Closed
Assignees

Comments

@kraenhansen
Copy link
Member

kraenhansen commented Feb 1, 2022

Problem

Currently our Dictionary#add method takes an object, like this:

dict.set({ key: value });

I see a couple of issues with this approach:

  • When the key is only known at runtime, end users need to either:
    i. Construct an object before calling the method: const values = {}; values[key] = value; dict.set(values);
    i. Or use the less known square-bracket syntax: dict.set({ [key]: value });
  • It's unclear (from the documentation) if a user can set multiple key-value pairs this way.

It is however nice that a user can assign multiple key-value pairs in a single method call.

Solution

I suggest migrating towards a more Map-like API:

dict.set(key, value);

We should detect that the method is called with two arguments and provide this as an overload to the existing method.

How important is this improvement for you?

I'd like to see it, but have a workaround

@kraenhansen kraenhansen changed the title Update Dictionary#add signature to take two arguments: key and value Update Dictionary#set signature to take two arguments: key and value Jan 30, 2023
@sync-by-unito
Copy link

sync-by-unito bot commented Feb 3, 2023

➤ papafe commented:

Not sure if this should have documentation changes, I don't know how much in details we usually go in the docs

@sync-by-unito
Copy link

sync-by-unito bot commented Feb 3, 2023

➤ kraenhansen commented:

I think it should, it's essentially a new overload to the method with its own doc comment.

This page might also need to update (for RN and React Native): https://www.mongodb.com/docs/realm/sdk/react-native/realm-database/schemas/dictionaries/

@sync-by-unito sync-by-unito bot closed this as completed Feb 15, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants