Skip to content

Commit

Permalink
fix a bug, that prevented datasource from being updated when used in …
Browse files Browse the repository at this point in the history
…context of performWithoutAnimations method of MemoryStorage.
  • Loading branch information
DenTelezhkin committed Feb 1, 2018
1 parent a662276 commit c5cfd07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.

# Next

* Fixed a bug, that prevented datasource from being updated when `updateWithoutAnimations` method on `MemoryStorage` was used.

## [7.0.0](https://github.com/DenHeadless/DTModelStorage/releases/tag/7.0.0)

## [7.0.0-beta.1](https://github.com/DenHeadless/DTModelStorage/releases/tag/7.0.0-beta.1)
Expand Down
14 changes: 13 additions & 1 deletion Source/Core/MemoryStorage+UpdateWithoutAnimations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,20 @@ extension MemoryStorage
open func updateWithoutAnimations(_ block: () -> Void)
{
let delegate = self.delegate
self.delegate = nil
let recordingDelegate = RecordingDelegate()
self.delegate = recordingDelegate
block()
recordingDelegate.update?.applyDeferredDatasourceUpdates()
self.delegate = delegate
}
}

private class RecordingDelegate: StorageUpdating {
var update : StorageUpdate?

func storageDidPerformUpdate(_ update: StorageUpdate) {
self.update = update
}

func storageNeedsReloading() {}
}
4 changes: 3 additions & 1 deletion Tests/Specs/MemoryStorage/MemoryStorageSearchSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ class MemoryStorageSearchSpec: XCTestCase {
}

func testUpdateWithoutAnimations() {
storage.defersDatasourceUpdates = true
storage.updateWithoutAnimations {
expect(self.storage.delegate).to(beNil())
storage.addItems([1,2])
}
expect(self.storage.items(inSection: 0)?.flatMap { $0 as? Int} ?? []) == [1,2]
}

func testEmptySection()
Expand Down

0 comments on commit c5cfd07

Please sign in to comment.