Skip to content

Commit 112bb8a

Browse files
committed
Refine README merge hook examples
1 parent 26fde1a commit 112bb8a

File tree

2 files changed

+2
-45
lines changed

2 files changed

+2
-45
lines changed

README.md

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -299,31 +299,7 @@ await kit.registerMergeHook { input in
299299

300300
### Real-World Examples
301301

302-
**Deduplication:**
303-
304-
```swift
305-
await kit.registerMergeHook { input in
306-
for context in input.contexts {
307-
await context.perform {
308-
for transaction in input.transactions {
309-
guard let changes = transaction.changes else { continue }
310-
311-
for change in changes where change.changeType == .insert {
312-
guard let object = try? context.existingObject(with: change.changedObjectID),
313-
let uniqueID = object.value(forKey: "uniqueID") as? String else {
314-
continue
315-
}
316-
317-
// Find duplicates and remove
318-
// ... deduplication logic
319-
}
320-
}
321-
try? context.save()
322-
}
323-
}
324-
return .goOn
325-
}
326-
```
302+
Merge Hooks can customize the merge pipeline itself, for example by temporarily disabling `undoManager` while applying history transactions.
327303

328304
**📚 Complete Hook Documentation:** [Docs/HookMechanism.md](Docs/HookMechanism.md)
329305

READMECN.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -255,26 +255,7 @@ await kit.registerMergeHook { input in
255255
}
256256
```
257257

258-
**实战示例:去重**
259-
260-
```swift
261-
await kit.registerMergeHook { input in
262-
for context in input.contexts {
263-
await context.perform {
264-
for transaction in input.transactions {
265-
guard let changes = transaction.changes else { continue }
266-
for change in changes where change.changeType == .insert {
267-
guard let object = try? context.existingObject(with: change.changedObjectID),
268-
let uniqueID = object.value(forKey: "uniqueID") as? String else { continue }
269-
// 根据 uniqueID 查找重复项并删除
270-
}
271-
}
272-
try? context.save()
273-
}
274-
}
275-
return .goOn
276-
}
277-
```
258+
Merge Hook 可以直接介入合并流水线,例如在应用 history transaction 时临时禁用 `undoManager`
278259

279260
完整 Hook 指南:[`Docs/HookMechanismCN.md`](Docs/HookMechanismCN.md)
280261

0 commit comments

Comments
 (0)