neallester / danake-sw

A persistence framework in Swift.
MIT License
3 stars 0 forks source link

Implement Conditional Entity Item Updates #2

Open neallester opened 6 years ago

neallester commented 6 years ago

Add to class Entity:

    public func asyncIfUpdated (batch: Batch, closure: @escaping (inout T) -> Void) {}

    public func syncIfUpdated (batch: Batch, closure: @escaping (inout T) -> Void) {}

which adds self to the batch (and updates persistentState) only if a persistent attribute in the item was actually changed. One implementation: serialize item before and after executing closure and doing the update only if they differ.