From 306c939afe28e768027c08930204ebed2e2811d3 Mon Sep 17 00:00:00 2001 From: Fumito Ito Date: Wed, 28 Mar 2018 11:49:05 +0900 Subject: [PATCH 1/4] `tableNode(_:,nodeForRowAt:)` should be called on main thread --- .../ASTableNode+Rx/ASTableSectionedDataSource.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift b/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift index e39932c..abb51eb 100644 --- a/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift +++ b/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift @@ -35,7 +35,8 @@ open class ASTableSectionedDataSource: NSObject, ASTableDat } fileprivate static func configureCellBlockNotSet(dataSource: ASTableSectionedDataSource, node: ASTableNode, indexPath: IndexPath, model: I) -> ASCellNodeBlock { - return { dataSource.tableNode(node, nodeForRowAt: indexPath) } + // Users expect taleNode(_:nodeForRowAt:) will be executed in main thread according to api doc http://texturegroup.org/appledoc/Protocols/ASTableDataSource.html#//api/name/tableNode:nodeForRowAtIndexPath: . + return { DispatchQueue.main.sync(execute: { dataSource.tableNode(node, nodeForRowAt: indexPath) }) } } #if os(iOS) From 3bd6363ca23adf22a28b3632b3b7e78ccca6ed40 Mon Sep 17 00:00:00 2001 From: Fumito Ito Date: Thu, 16 Aug 2018 08:54:54 +0900 Subject: [PATCH 2/4] execute some delegate in main thread --- .../ASCollectionSectionedDataSource.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift b/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift index a293fc2..86e0133 100644 --- a/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift +++ b/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift @@ -29,11 +29,13 @@ open class ASCollectionSectionedDataSource: NSObject, ASCol } fileprivate static func configureCellBlockNotSet(dataSource: ASCollectionSectionedDataSource, node: ASCollectionNode, indexPath: IndexPath, model: I) -> ASCellNodeBlock { - return { dataSource.collectionNode(node, nodeForItemAt: indexPath) } + // Users expect collectionNode(_:nodeForItemAt:) will be executed in main thread according to api doc (http://texturegroup.org/appledoc/Protocols/ASCollectionDataSource.html#//api/name/collectionView:nodeForItemAtIndexPath:). + return { DispatchQueue.main.sync(execute: { dataSource.collectionNode(node, nodeForItemAt: indexPath) }) } } fileprivate static func configureSupplementaryViewBlockNotSet(dataSource: ASCollectionSectionedDataSource, node: ASCollectionNode, nodeForSupplementaryElementOfKind kind: String, indexPath: IndexPath) -> ASCellNodeBlock { - return { dataSource.collectionNode(node, nodeForSupplementaryElementOfKind: kind, at: indexPath) } + // Users expect collectionNode(_nodeForSupplementaryElementOfKind:at:) will be executed in main thread according to api doc. + return { DispatchQueue.main.sync(execute: { dataSource.collectionNode(node, nodeForSupplementaryElementOfKind: kind, at: indexPath) }) } } public init( From c81139215bee2c307198532f57754b69ae3cd3c3 Mon Sep 17 00:00:00 2001 From: Fumito Ito Date: Thu, 16 Aug 2018 08:55:04 +0900 Subject: [PATCH 3/4] format --- .../ASTableNode+Rx/RxASTableAnimatedDataSource.swift | 2 +- .../DataSources/ASTableNode+Rx/RxASTableReloadDataSource.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/DataSources/ASTableNode+Rx/RxASTableAnimatedDataSource.swift b/Sources/DataSources/ASTableNode+Rx/RxASTableAnimatedDataSource.swift index 0a64996..8cf9269 100644 --- a/Sources/DataSources/ASTableNode+Rx/RxASTableAnimatedDataSource.swift +++ b/Sources/DataSources/ASTableNode+Rx/RxASTableAnimatedDataSource.swift @@ -150,6 +150,6 @@ open class RxASTableAnimatedDataSource: ASTableSe tableNode.reloadData() } } - }.on(observedEvent) + }.on(observedEvent) } } diff --git a/Sources/DataSources/ASTableNode+Rx/RxASTableReloadDataSource.swift b/Sources/DataSources/ASTableNode+Rx/RxASTableReloadDataSource.swift index 365ab88..08b1cd3 100644 --- a/Sources/DataSources/ASTableNode+Rx/RxASTableReloadDataSource.swift +++ b/Sources/DataSources/ASTableNode+Rx/RxASTableReloadDataSource.swift @@ -29,6 +29,6 @@ open class RxASTableReloadDataSource: ASTableSectionedDataS dataSource.setSections(element) tableNode.reloadData() } - }.on(observedEvent) + }.on(observedEvent) } } From e0758519402600f42ccf62aacd182963f8b4fbdb Mon Sep 17 00:00:00 2001 From: Fumito Ito Date: Sat, 11 May 2019 22:27:16 +0900 Subject: [PATCH 4/4] catch PatrickChow's comment --- .../ASCollectionSectionedDataSource.swift | 5 +++-- .../ASTableNode+Rx/ASTableSectionedDataSource.swift | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift b/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift index 86e0133..010f705 100644 --- a/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift +++ b/Sources/DataSources/ASCollectionNode+Rx/ASCollectionSectionedDataSource.swift @@ -29,8 +29,9 @@ open class ASCollectionSectionedDataSource: NSObject, ASCol } fileprivate static func configureCellBlockNotSet(dataSource: ASCollectionSectionedDataSource, node: ASCollectionNode, indexPath: IndexPath, model: I) -> ASCellNodeBlock { - // Users expect collectionNode(_:nodeForItemAt:) will be executed in main thread according to api doc (http://texturegroup.org/appledoc/Protocols/ASCollectionDataSource.html#//api/name/collectionView:nodeForItemAtIndexPath:). - return { DispatchQueue.main.sync(execute: { dataSource.collectionNode(node, nodeForItemAt: indexPath) }) } + // Users expect collectionNode(_:nodeForItemAt:) will be executed in main thread + let cellNode = dataSource.collectionNode(node, nodeForItemAt: indexPath) + return { cellNode } } fileprivate static func configureSupplementaryViewBlockNotSet(dataSource: ASCollectionSectionedDataSource, node: ASCollectionNode, nodeForSupplementaryElementOfKind kind: String, indexPath: IndexPath) -> ASCellNodeBlock { diff --git a/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift b/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift index abb51eb..1a15674 100644 --- a/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift +++ b/Sources/DataSources/ASTableNode+Rx/ASTableSectionedDataSource.swift @@ -35,8 +35,9 @@ open class ASTableSectionedDataSource: NSObject, ASTableDat } fileprivate static func configureCellBlockNotSet(dataSource: ASTableSectionedDataSource, node: ASTableNode, indexPath: IndexPath, model: I) -> ASCellNodeBlock { - // Users expect taleNode(_:nodeForRowAt:) will be executed in main thread according to api doc http://texturegroup.org/appledoc/Protocols/ASTableDataSource.html#//api/name/tableNode:nodeForRowAtIndexPath: . - return { DispatchQueue.main.sync(execute: { dataSource.tableNode(node, nodeForRowAt: indexPath) }) } + // Users expect taleNode(_:nodeForRowAt:) will be executed in main thread + let cellNode = dataSource.tableNode(node, nodeForRowAt: indexPath) + return { cellNode } } #if os(iOS)