You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the only available setter Store.set() either sets a single item or takes an object to set multiple values. Providing an object would overwrite the whole value, which is a normal/expected behavior. Though, this leaves out use cases where we want to update multiple fields at a path in one go.
Example:
conststore=newStore();store.store={users: {p9dsbfo0b0sbd: {name: 'John Smith',email: '[email protected]',age: 52,occupation: {title: 'Web Developer',remote: false}}}};// Updating multiple values (we'll either lose 'email' and 'occupation.title' fields or a schema validation error is thrown)store.set('users.p9dsbfo0b0sbd',{name: 'John M. Smith',age: 53,occupation: {remote: true}});// Must dostore.set('users.p9dsbfo0b0sbd.name','John M. Smith');store.set('users.p9dsbfo0b0sbd.age',53);store.set('users.p9dsbfo0b0sbd.occupation.remote',true);// Better be able to do (object should be merged deeply)store.update('users.p9dsbfo0b0sbd',{name: 'John M. Smith',age: 53,occupation: {remote: true}});
The text was updated successfully, but these errors were encountered:
@sindresorhus I think deep merging is more practical, but users might expect a shallow merge based on other database operators such as MongoDB. We can however provide both methods through either:
Currently the only available setter
Store.set()
either sets a single item or takes an object to set multiple values. Providing an object would overwrite the whole value, which is a normal/expected behavior. Though, this leaves out use cases where we want to update multiple fields at a path in one go.Example:
The text was updated successfully, but these errors were encountered: