Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.87k stars 1.54k forks source link

Make diff code available as a separate component #53

Closed insidegui closed 7 years ago

insidegui commented 8 years ago

It would be useful to have just the diff algorithm implementation and related protocol used in IGListKit available as a separate component to be used for other purposes (i.e. table views, existing apps that don't want to migrate to IGListKit but want the diffing).

rnystrom commented 8 years ago

@insidegui you're in luck, it already is!

If you add IGListKit to your app you can use the diffing by itself. There's an example in the readme for this, but basically:

#import <IGListKit/IGListKit.h>

NSArray *oldStuff = @[...];
NSArray *newStuff = @[...];
IGListIndexSetResult *result = IGListDiff(oldStuff, newStuff, IGListDiffEquality);
// or if you want index paths, where the first two ints are the from/to sections
IGListIndexPathResult *result = IGListDiffPaths(0, 0, oldStuff, newStuff, IGListDiffEquality);

Then you can use the result objects to update the UICollectionView or UITableView. You can use the algorithm and IGListDiffable protocol however/wherever you want.

Now if you want to use the diffing w/out importing the rest of IGListKit (which is arguably not a big framework to add), we might be able to add another Cocoapods spec for that, but I'm not sure its worth the effort of maintaining a separate workspace/tests/etc for that yet.

insidegui commented 8 years ago

Awesome! I think it would be useful to have a separate spec, especially since the framework doesn't support macOS yet but the diff code does.

rnystrom commented 8 years ago

Good point re: macOS

laptobbe commented 7 years ago

@rnystrom Would having it as a subspec in CocoaPods require it to be a separate workspace? If not, maybe that could be solution?

rnystrom commented 7 years ago

@laptobbe I'm not sure tbh, I'll have to do a little research to see what options we have. The most important things for this will be:

Ideally I'd love to make another IGListDiffKit.podspec within this repo that only has a select few files as the source, then someone can pod IGListDiffKit and get everything.

Also, importing the entire IGListKit lib isn't that much of a binary size hit, and you can use the diffing algo by itself still. We even have an example of this.

jessesquires commented 7 years ago

Would having it as a subspec in CocoaPods require it to be a separate workspace? If not, maybe that could be solution?

CocoaPods subspec should do the trick, without requiring any major changes. The subspec could specify macOS target compatibility too. (As far as I know.)

I think a subspec gets us 90% of the way there. The problem is that this forces clients to use CocoaPods. (But I like CocoaPods, so ¯\_(ツ)_/¯)

Also, importing the entire IGListKit lib isn't that much of a binary size hit, and you can use the diffing algo by itself still.

Right, but not on macOS or watchOS. (Because of UICollectionView)

insidegui commented 7 years ago

I actually made a little repo for myself with the diffing part isolated, the only source changes I had to make involved adding #if TARGET_OS_OSX checks to the umbrella header and IGListDiffCore.mm to import Cocoa on macOS and UIKit on iOS. I am using Carthage so I didn't make a podspec for it.

jessesquires commented 7 years ago

@insidegui -- It is possible to create cross-platform frameworks. Would you want to submit a PR to do this?

Actually -- we should be able to add a macOS target, guard necessary areas with #if TARGET_OS_OSX, and only include the diffing files in the macOS target.

jessesquires commented 7 years ago

An example of a cross-platform ObjC framework: https://github.com/jessesquires/JSQSystemSoundPlayer

(Slightly different, because this doesn't use UIKit or any iOS specific APIs. But, the general idea is the same.)

insidegui commented 7 years ago

Would you want to submit a PR to do this?

I am working on this, will open the PR soon ;)

insidegui commented 7 years ago

There you go: https://github.com/Instagram/IGListKit/pull/235

Sherlouk commented 7 years ago

@jessesquires Flagging for closure

jessesquires commented 7 years ago

Done in #368