Coder Social home page Coder Social logo

flexiblediff's Introduction

Introduction

FlexibleDiff is a simple collection diffing μframework for Swift, allowing separated defintions of identity and equality for the purpose of diffing.

For general business concerns, full inequality of two instances does not necessarily mean inequality in term of identity — it just means the data being held has changed if the identity of both instances are the same. However, as most of the diffing μframeworks rely on only — and therefore are constrained by — the Equatable requirement, they are not capable of expressing the identical-but-unequal scenarios which are common especially in interactive applications.

FlexibleDiff addresses the issue by supporting changeset computation with custom definitions for equality and identity.

For example, given these definitions:

let previous: [Book]
let current: [Book]

struct Book: Equatable {
    let isbn: String
    var name: String
    var publishedOn: [Date]
}

We may supply a custom identity definition, and get to know about in-place mutated books, or mutated books at a different position, on the basis of books being identified only by their ISBN.

let changeset = Changeset(previous: previous,
                          current: current,
                          identifier: { book in book.isbn },
                          areEqual: Book.==)

The improved expressivity of the diff, as compared to conventional Equatable -based μframeworks, allows more fitting collection view animations to be issued.

On top of the flexible API, FlexibleDiff provides also several conveniences for common use cases:

Collection.Element Identified By Compared By
AnyObject Object identity Object identity
AnyObject & Equatable Object identity Object identity or value equality.
AnyObject & Hashable Object identity, or value equality. Object identity, or value equality.
Hashable Value equality Value equality

Getting Started

FlexibleDiff is offered as a standalone Xcode project, and supports both Carthage and CocoaPods.

# Carthage
github "RACCommunity/FlexibleDiff"

# CocoaPods
pod "FlexibleDiff"

The Example App

The Xcode workspace includes an example app using FlexibleDiff. Be sure to run git submodule update --init to fetch the dependencies before building the app target in Xcode.

Note on the algorithm

The implementation is evolved from the popular O(n) diff algorithm by Paul Heckel, in his 1978 paper "A technique for isolating differences between files". The algorithm serves as the basis of many frameworks across multiple platforms, including but not limited to IGListKit.

License

Licensed under the MIT License.

flexiblediff's People

Contributors

andersio avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.