|
| 1 | +--- |
| 2 | +"@homeostate/core": minor |
| 3 | +--- |
| 4 | + |
| 5 | +Breaking: `Change` is a discriminated union of objects instead of a `[type, key, value]` tuple, |
| 6 | +and `ChangeType` is a const object instead of an `enum`. A script holds one kind of step: |
| 7 | +`RecordChange` for a record, keyed by property name, and `ListChange` or `TextChange` for an |
| 8 | +array or a string, keyed by position. `getChanges` returns the script of the kind of the values |
| 9 | +it diffs, or an `EditScript` for values typed only as `Diffable`, and `applyStringChanges` takes |
| 10 | +a `TextChange[]`. Narrowing a step by `type`, and a pending step by `kind`, replaces the casts. |
| 11 | + |
| 12 | +Adjacent array items or characters deleted together are now one `delete` step with a `count`, |
| 13 | +which `applyChanges` passes to `splice` or `editText` as one call. Clearing a 5000-item list or a |
| 14 | +5000-character text through the Yjs backend takes one `delete` instead of 5000, and about 1 ms |
| 15 | +instead of 100 to 250 ms. |
| 16 | + |
| 17 | +To migrate code that reads or builds changes: |
| 18 | + |
| 19 | +- Destructure properties instead of the tuple: `const { type, key } = change`. An insert or |
| 20 | + update carries `value`; a pending step carries `kind` (`"record"`, `"list"` or `"text"`) and |
| 21 | + its nested `changes`, which used to be its third entry. |
| 22 | +- Apply an array or string delete's `count`, treating an absent one as `1`. A string delete's |
| 23 | + length used to be its third entry. `getChanges` sets it on every array and string delete. |
| 24 | +- `ChangeType.INSERT` and the other members keep their values, and `ChangeType` is still the |
| 25 | + type of the four strings. Code that relied on the `enum` type, rather than its values, now |
| 26 | + takes the string literals. |
| 27 | +- Annotate scripts as `RecordChange[]`, `ListChange[]`, `TextChange[]` or `EditScript` instead of |
| 28 | + `Change[]`, which is a single step of any kind. |
| 29 | + |
| 30 | +`ApplyOps` is unchanged, so backends and stores that apply changes through `applyChanges` need |
| 31 | +no change. |
0 commit comments