Skip to content

Commit 3ff6fa7

Browse files
committed
update docs to increase clarity (expecially about unsupported edge cases)
1 parent 9bde96b commit 3ff6fa7

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

docs/edge-cases.md

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Edge cases
22

3-
Structura supports some edge cases that are not always well handled by other libraries.
3+
Structura supports some edge cases that are not always well handled by other libraries. On the contrary, some edge cases are not well supported.
44

55
## Returning and modifying in the same producer
66

@@ -68,35 +68,21 @@ const newState5 = produce(state, (draft) => {
6868
})
6969
```
7070

71-
## Transpositions
71+
## Assigning draftable objects to non draftable objects
7272

73-
You can reassign the key of a sub-object and the result will be what you expect
74-
75-
Besides, this will not work if you assign to an object external from the draft
73+
If you try assigning a draftable object to a non draftable object as a sub property, you will be left with a dangling proxy
7674

7775
```typescript
7876
const state = [[1], [2]]
7977

80-
// this works well
81-
const newState1 = produce(state, (draft) => {
82-
const first = draft[0]
83-
draft[0] = draft[1]
84-
draft[1] = first
85-
})
86-
87-
// this also works
88-
const newState2 = produce(state, (draft) => {
89-
const first = draft[0]
90-
draft[0] = draft[1]
91-
draft[1] = first
92-
first.push(9999)
93-
})
94-
9578
// this does not work well because the new object
96-
// will remain with a proxy attached via its prop
79+
// will remain with a proxy attached via its prop;
80+
9781
const newState3 = produce(state, (draft) => {
9882
const first = draft[0]
9983
const newObj = { prop: first }
10084
draft.push(newObj as any)
10185
})
86+
87+
// newState3[2].prop is a proxy
10288
```

docs/when-to-use.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
- test coverage is still not 100%
1616
- docs could be better
1717
- does not support IE and pre ES6 browsers and will never do
18-
- does not yet support ~~some proxy traps and~~ some data structures that Immer supports, but this is very likely to change in the future
18+
- does not yet support ~~some proxy traps and~~ an edge case that Immer supports ([this](./edge-cases.md#assigning-draftable-objects-to-non-draftable-objects)), but this is very likely to change in the future
1919
- generated patches are not compliant to any RFC, but ~~in the future this may change or there could be a converter~~ there is already a converter included in the library; besides applyPatches also accept standard JSON Patches

0 commit comments

Comments
 (0)