Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DifferenceKit #12

Merged
merged 10 commits into from
Jan 11, 2022
Merged

Use DifferenceKit #12

merged 10 commits into from
Jan 11, 2022

Conversation

muukii
Copy link
Collaborator

@muukii muukii commented Aug 7, 2018

  • Implement
  • Update Readme

@muukii
Copy link
Collaborator Author

muukii commented Aug 7, 2018

2018-08-07 17:38:22.610091+0900 DataSourcesDemo[18119:4824139] Attempt to delete and reload the same item at index path <NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2}
2018-08-07 17:38:22.640530+0900 DataSourcesDemo[18119:4824139] *** Terminating app due to uncaught exception 'ASCollectionInvalidUpdateException', reason: 'DataSourcesDemo.MultipleSectionCollectionNodeViewController: Attempt to delete and reload the same item at index path <NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2}'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000115f361e6 __exceptionPreprocess + 294
	1   libobjc.A.dylib                     0x000000011117c031 objc_exception_throw + 48
	2   CoreFoundation                      0x0000000115fab975 +[NSException raise:format:] + 197
	3   AsyncDisplayKit                     0x000000010ff70c2e -[ASDataController updateWithChangeSet:] + 3438
	4   AsyncDisplayKit                     0x000000010ff4763f -[ASCollectionView endUpdatesAnimated:completion:] + 1503
	5   AsyncDisplayKit                     0x000000010ff47913 -[ASCollectionView performBatchAnimated:updates:completion:] + 611
	6   AsyncDisplayKit                     0x000000010ff3afe3 -[ASCollectionNode performBatchAnimated:updates:completion:] + 659
	7   DataSourcesDemo                     0x000000010fb72fb8 _T015DataSourcesDemo21CollectionNodeAdapterC12performBatchySb8animated_yyc7updatesyyc10completiontF + 504
	8   DataSourcesDemo                     0x000000010fb7355f _T015DataSourcesDemo21CollectionNodeAdapterC0aB08UpdatingAadEP12performBatchySb8animated_yyc7updatesyyc10completiontFTW + 15
	9   DataSources                         0x0000000110b063fd _T011DataSources14SectionUpdaterC6updateySi06targetC0_SayxG22currentDisplayingItemsAF03newI0AC10UpdateModeOyxq__G0eL0yyc10completiontF + 1917
	10  DataSources                         0x0000000110b03a67 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU_ + 775
	11  DataSources                         0x0000000110b03b56 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU_TA + 86
	12  DataSources                         0x0000000110b03bb7 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU0_ + 23
	13  DataSources                         0x0000000110b03c11 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU0_TA + 17
	14  DataSources                         0x0000000110afb75f _T011DataSources8ThrottleC2onyyyc7handler_tFyycfU_ + 367
	15  DataSources                         0x0000000110afb9a9 _T011DataSources8ThrottleC2onyyyc7handler_tFyycfU_TA + 25
	16  DataSources                         0x0000000110afb9dd _T0Ieg_IeyB_TR + 45
	17  libdispatch.dylib                   0x00000001168587ec _dispatch_client_callout + 8
	18  libdispatch.dylib                   0x000000011685ead9 _dispatch_continuation_pop + 967
	19  libdispatch.dylib                   0x0000000116869f4a _dispatch_source_invoke + 1635
	20  libdispatch.dylib                   0x0000000116863b42 _dispatch_main_queue_callback_4CF + 1255
	21  CoreFoundation                      0x0000000115ef8c99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	22  CoreFoundation                      0x0000000115ebcea6 __CFRunLoopRun + 2342
	23  CoreFoundation                      0x0000000115ebc30b CFRunLoopRunSpecific + 635
	24  GraphicsServices                    0x000000011b4cfa73 GSEventRunModal + 62
	25  UIKit                               0x000000011212d057 UIApplicationMain + 159
	26  DataSourcesDemo                     0x000000010fb87307 main + 55
	27  libdyld.dylib                       0x00000001168d5955 start + 1
	28  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@muukii
Copy link
Collaborator Author

muukii commented Aug 7, 2018

In shuffle

2018-08-07 17:44:02.373155+0900 DataSourcesDemo[18441:4834147] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to perform a delete and a move from the same index path (<NSIndexPath: 0xc000000002600016> {length = 2, path = 0 - 19})'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000109ad61e6 __exceptionPreprocess + 294
	1   libobjc.A.dylib                     0x00000001050e9031 objc_exception_throw + 48
	2   CoreFoundation                      0x0000000109adb472 +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x0000000104b8c652 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
	4   UIKit                               0x0000000106b76d89 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 5330
	5   UIKit                               0x0000000106b8200e -[UICollectionView _endUpdatesWithInvalidationContext:tentativelyForReordering:animator:] + 71
	6   UIKit                               0x0000000106b82357 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:] + 439
	7   UIKit                               0x0000000106b8217d -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:] + 91
	8   UIKit                               0x0000000106b820ff -[UICollectionView _performBatchUpdates:completion:invalidationContext:] + 74
	9   UIKit                               0x0000000106b82054 -[UICollectionView performBatchUpdates:completion:] + 53
	10  DataSources                         0x0000000104a66cea _T011DataSources21CollectionViewAdapterC12performBatchySb8animated_yyc7updatesyyc10completiontF + 586
	11  DataSources                         0x0000000104a675a8 _T011DataSources21CollectionViewAdapterCAA8UpdatingA2aDP12performBatchySb8animated_yyc7updatesyyc10completiontFTW + 24
	12  DataSources                         0x0000000104a733fd _T011DataSources14SectionUpdaterC6updateySi06targetC0_SayxG22currentDisplayingItemsAF03newI0AC10UpdateModeOyxq__G0eL0yyc10completiontF + 1917
	13  DataSources                         0x0000000104a70a67 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU_ + 775
	14  DataSources                         0x0000000104a70b56 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU_TA + 86
	15  DataSources                         0x0000000104a70bb7 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU0_ + 23
	16  DataSources                         0x0000000104a70c11 _T011DataSources07SectionA10ControllerC6updateySayxG5items_AC10UpdateModeOyxq__G0eH0Sb11immediatelyyyc10completiontFyycfU0_TA + 17
	17  DataSources                         0x0000000104a6875f _T011DataSources8ThrottleC2onyyyc7handler_tFyycfU_ + 367
	18  DataSources                         0x0000000104a689a9 _T011DataSources8ThrottleC2onyyyc7handler_tFyycfU_TA + 25
	19  DataSources                         0x0000000104a689dd _T0Ieg_IeyB_TR + 45
	20  libdispatch.dylib                   0x000000010a7087ec _dispatch_client_callout + 8
	21  libdispatch.dylib                   0x000000010a70ead9 _dispatch_continuation_pop + 967
	22  libdispatch.dylib                   0x000000010a719f4a _dispatch_source_invoke + 1635
	23  libdispatch.dylib                   0x000000010a713b42 _dispatch_main_queue_callback_4CF + 1255
	24  CoreFoundation                      0x0000000109a98c99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	25  CoreFoundation                      0x0000000109a5cea6 __CFRunLoopRun + 2342
	26  CoreFoundation                      0x0000000109a5c30b CFRunLoopRunSpecific + 635
	27  GraphicsServices                    0x000000010f43da73 GSEventRunModal + 62
	28  UIKit                               0x000000010609a057 UIApplicationMain + 159
	29  DataSourcesDemo                     0x0000000103af4307 main + 55
	30  libdyld.dylib                       0x000000010a785955 start + 1
	31  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@ra1028
Copy link

ra1028 commented Aug 8, 2018

Thanks @muukii
StagedChangeset applies batch-updates in stages.
Therefore, to solve this probrem, performBatchUpdates needs to be called once for each stage, and before each that needs to assign the data of the collection that Changeset has to the data that the dataSource refers to.

See also here
and Example App

@ra1028
Copy link

ra1028 commented Aug 8, 2018

Also, in isUpdated(from:), will detect updates by returning true.
I know that the this interface has room for improvement.

@muukii
Copy link
Collaborator Author

muukii commented Aug 21, 2018

@ra1028
Thank you for your advice.
I misunderstood isUpdate.
It worked on a fix!!

@muukii
Copy link
Collaborator Author

muukii commented Aug 21, 2018

In addition, separating performBatch caused a crash(assertion) by a pair of adding and removing.
Because, the number of items must be -1 when only removing.

@ra1028
Copy link

ra1028 commented Aug 21, 2018

@muukii
I think you may still misunderstood.
StagedChangeset expects to run performBatch every stages.
As follows:

for changeset in stagedChangeset {

    self.adapter.performBatch(
        animated: animated,
        updates: {
            if !changeset.elementDeleted.isEmpty {
                _adapter.deleteItems(at: changeset.elementDeleted.map { IndexPath(item: $0.element, section: $0.section) })
            }

            if !changeset.elementInserted.isEmpty {
                _adapter.insertItems(at: changeset.elementInserted.map { IndexPath(item: $0.element, section: $0.section) })
            }

            if !changeset.elementUpdated.isEmpty {
                _adapter.reloadItems(at: changeset.elementUpdated.map { IndexPath(item: $0.element, section: $0.section) })
            }

            for (source, target) in changeset.elementMoved {
                _adapter.moveItem(
                    at: IndexPath(item: source.element, section: source.section),
                    to: IndexPath(item: target.element, section: target.section)
                )
            }
    })
}

@ra1028
Copy link

ra1028 commented Aug 21, 2018

However, DifferenceKit is now on alpha release, and the API continues to change.
Maybe the API will stable in the next release v0.5.0.

@muukii muukii force-pushed the muukii/differenceKit branch 2 times, most recently from 768e4ad to 1f04426 Compare December 18, 2018 11:39
muukii added 3 commits October 4, 2019 11:45
Revise

Revise

Update podspec

Revise

:zap: WIP

:zap: WIP
@muukii muukii force-pushed the muukii/differenceKit branch from bdfc14e to 4ff5eeb Compare October 4, 2019 03:14
@muukii
Copy link
Collaborator Author

muukii commented Jan 26, 2020

Almost done.
Readme should be updated.

@muukii muukii merged commit ac94577 into master Jan 11, 2022
@muukii muukii deleted the muukii/differenceKit branch January 11, 2022 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants