Open ramtinsoltani opened 1 year ago
Seems useful to me.
Is it expected to a user that it does deep merging though?
@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:
// Additional argument
update(key: string, object: any, deepMerge: boolean = false)
// Example
store.update('users.p9dsbfo0b0sbd', {
name: 'John M. Smith',
age: 53,
occupation: {
remote: true
}
}, true);
or a different method altogether:
// Shallow merge
update(key: string, object: any)
// Deep merge
merge(key: string, object: any)
Though I personally prefer the first approach.
If you find this useful, once we agree on an approach, I can create a dependency-free PR for conf
.
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: