Skip to content

Commit

Permalink
Improve OpenItemsController items observer registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Apr 15, 2024
1 parent 7583ed1 commit 21deedc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Zotero/Controllers/OpenItemsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ final class OpenItemsController {
var existingItems = getItems(for: sessionIdentifier)
if let index = existingItems.firstIndex(where: { $0.kind == kind }) {
existingItems[index].lastOpened = .now
// No need to call setItems, to register a new items observer, as only items metadata were updated.
itemsBySessionIdentifier[sessionIdentifier] = existingItems
DDLogInfo("OpenItemsController: already opened item \(kind) became most recent for \(sessionIdentifier)")
observable(for: sessionIdentifier).on(.next(existingItems))
Expand Down Expand Up @@ -204,7 +205,8 @@ final class OpenItemsController {
var itemsChanged: Bool = false
defer {
if itemsChanged {
observable(for: sessionIdentifier).on(.next(existingItems))
// setItems will produce next observable event
setItems(existingItems, for: sessionIdentifier, validate: false)
}
}
var item: Item?
Expand Down

0 comments on commit 21deedc

Please sign in to comment.