Skip to content

Commit

Permalink
Fix/single data source replace object (#38)
Browse files Browse the repository at this point in the history
* If an object is deleted and created at the same time for a `SingleCoreDataSource`, then issue two calls to the update handler

* Version
  • Loading branch information
lj-dickey authored Jun 5, 2020
1 parent 34d3143 commit 385a45b
Show file tree
Hide file tree
Showing 76 changed files with 164 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Flapjack.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Flapjack'
s.version = '0.6.1'
s.version = '0.6.2'
s.summary = 'A Swift data persistence API with support for Core Data.'
s.description = <<-DESC
Flapjack is an iOS/macOS/tvOS framework with 2 primary goals.
Expand Down
1 change: 0 additions & 1 deletion Flapjack/CoreData/SingleCoreDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public class SingleCoreDataSource<T: NSManagedObject & DataObject>: NSObject, Si
hasFetched = true
object = nil
onChange?(nil)
return
}

let theRest = inserts.union(updates).union(refreshes)
Expand Down
17 changes: 17 additions & 0 deletions Tests/CoreData/SingleCoreDataSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,21 @@ class SingleCoreDataSourceTests: XCTestCase {
waitForExpectations(timeout: 0.5) { XCTAssertNil($0) }
XCTAssertEqual(dataSource.object, newEntity)
}

func testObjectDidChangeBlockFiresTwiceWhenOldObjectIsDeletedAndNewOneCreated() {
let expect = expectation(description: "did change block")
expect.expectedFulfillmentCount = 3
dataSource.onChange = { object in
expect.fulfill()
}
dataSource.startListening()

let newEntity = dataAccess.mainContext.create(MockEntity.self, attributes: attributes)
newEntity.someProperty = attributes["someProperty"]
dataAccess.mainContext.destroy(object: entity)
dataAccess.mainContext.persist()

waitForExpectations(timeout: 0.5) { XCTAssertNil($0) }
XCTAssertEqual(dataSource.object, newEntity)
}
}
6 changes: 3 additions & 3 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -421,7 +421,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/oreillymedia/flapjack/tree/master/Flapjack/CoreData/SingleCoreDataSource.swift#L20-L158">Show on GitHub</a>
<a href="https://github.com/oreillymedia/flapjack/tree/master/Flapjack/CoreData/SingleCoreDataSource.swift#L20-L157">Show on GitHub</a>
</div>
</section>
</div>
Expand All @@ -434,7 +434,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/CoreDataAccess.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -734,7 +734,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/CoreDataAccess/StoreType.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -345,7 +345,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/CoreDataSource.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -1200,7 +1200,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/CoreDataSourceFactory.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -524,7 +524,7 @@ <h4>Return Value</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/Logger.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -445,7 +445,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/MigrationPolicy.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -358,7 +358,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/SingleCoreDataSource.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -693,7 +693,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -408,7 +408,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/DataAccessError.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -314,7 +314,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/DataContextError.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -402,7 +402,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/DataSourceChange.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -404,7 +404,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/DataSourceSectionChange.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -344,7 +344,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/LoggerLevel.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -345,7 +345,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/MigratorError.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -315,7 +315,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -643,7 +643,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Extensions/Array.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -287,7 +287,7 @@ <h4>Return Value</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
4 changes: 2 additions & 2 deletions docs/Extensions/NSFetchedResultsChangeType.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Flapjack 0.6.1 Docs
Flapjack 0.6.2 Docs
</a>
(93% documented)
</p>
Expand Down Expand Up @@ -253,7 +253,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-04-29)</p>
<p>&copy; 2020 <a class="link" href="https://oreilly.com" target="_blank" rel="external">O&#39;Reilly Media, Inc.</a>. All rights reserved. (Last updated: 2020-06-05)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
Loading

0 comments on commit 385a45b

Please sign in to comment.