mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-24 18:12:48 +03:00
example of type guards
This commit is contained in:
parent
9e310056e1
commit
843c213c07
@ -1,10 +1,22 @@
|
||||
import { Doc } from "yjs";
|
||||
import { diffChars } from "diff";
|
||||
|
||||
export type Delta =
|
||||
| { retain: number }
|
||||
| { delete: number }
|
||||
| { insert: string };
|
||||
type DeltaRetain = { retain: number };
|
||||
type DeltaDelete = { delete: number };
|
||||
type DeltaInsert = { insert: string };
|
||||
|
||||
export type Delta = DeltaRetain | DeltaDelete | DeltaInsert;
|
||||
|
||||
export namespace Delta {
|
||||
export const isRetain = (delta: Delta): delta is DeltaRetain =>
|
||||
"retain" in delta;
|
||||
|
||||
export const isDelete = (delta: Delta): delta is DeltaDelete =>
|
||||
"delete" in delta;
|
||||
|
||||
export const isInsert = (delta: Delta): delta is DeltaInsert =>
|
||||
"insert" in delta;
|
||||
}
|
||||
|
||||
// Compute the set of Yjs delta operations (that is, `insert` and
|
||||
// `delete`) required to go from initialText to finalText.
|
||||
|
Loading…
Reference in New Issue
Block a user