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
Copy file name to clipboardExpand all lines: readme.md
+56-1Lines changed: 56 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,34 @@
4
4
5
5
For _accessing_ deep object properties, please see [`dlv`](https://github.com/developit/dlv).
6
6
7
+
> **Using GraphQL?** You may want `dset/merge` – see [Merging](#merging) for more info.
The main/default `dset` module forcibly writes values at the assigned key-path. However, in some cases, you may prefer to _merge_ values at the key-path. For example, when using [GraphQL's `@stream` and `@defer` directives](https://foundation.graphql.org/news/2020/12/08/improving-latency-with-defer-and-stream-directives/), you will need to merge the response chunks into a single object/list. This is why `dset/merge` exists~!
92
+
93
+
Below is a quick illustration of the difference between `dset` and `dset/merge`:
94
+
95
+
```js
96
+
let input = {
97
+
hello: {
98
+
abc:123
99
+
}
100
+
};
101
+
102
+
dset(input, 'hello', { world:123 });
103
+
console.log(input);
104
+
105
+
// via `dset`
106
+
//=> {
107
+
//=> hello: {
108
+
//=> world: 123
109
+
//=> }
110
+
//=> }
111
+
112
+
// via `dset/merge`
113
+
//=> {
114
+
//=> hello: {
115
+
//=> abc: 123,
116
+
//=> world: 123
117
+
//=> }
118
+
//=> }
119
+
```
120
+
121
+
67
122
## Immutability
68
123
69
124
As shown in the examples above, all `dset` interactions mutate the source object.
@@ -72,8 +127,8 @@ If you need immutable writes, please visit [`clean-set`](https://github.com/fwil
72
127
Alternatively, you may pair `dset` with [`klona`](https://github.com/lukeed/klona), a 366B utility to clone your source(s). Here's an example pairing:
0 commit comments