All Projects → alexdrone → Buffer

alexdrone / Buffer

Licence: other
Swift μ-framework for efficient array diffs and datasource adapters.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Buffer

Diffabledatasources
💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.
Stars: ✭ 601 (+72.21%)
Mutual labels:  datasource, diffing, tableview
Differencekit
💻 A fast and flexible O(n) difference algorithm framework for Swift collection.
Stars: ✭ 2,986 (+755.59%)
Mutual labels:  diffing, tableview
Carbon
🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Stars: ✭ 1,034 (+196.28%)
Mutual labels:  datasource, diffing
Datasource
Simplifies the setup of UITableView data sources using type-safe descriptors for cells and sections. Animated diffing built-in.
Stars: ✭ 72 (-79.37%)
Mutual labels:  datasource, diffing
Modelassistant
Elegant library to manage the interactions between view and model in Swift
Stars: ✭ 26 (-92.55%)
Mutual labels:  datasource, tableview
Rxdatasources
UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)
Stars: ✭ 2,784 (+697.71%)
Mutual labels:  datasource, tableview
Containercontroller
UI Component. This is a copy swipe-panel from app: Apple Maps, Stocks. Swift version
Stars: ✭ 273 (-21.78%)
Mutual labels:  tableview
Dtcollectionviewmanager
Protocol-oriented UICollectionView management, powered by generics and associated types.
Stars: ✭ 300 (-14.04%)
Mutual labels:  datasource
Ace Diff
A diff/merging wrapper for Ace Editor built on google-diff-match-patch
Stars: ✭ 257 (-26.36%)
Mutual labels:  diffing
Awesome Ecommerce Stack
💰 Popular marketing tools and add-ons used by 10,000+ of the top e-commerce stores.
Stars: ✭ 255 (-26.93%)
Mutual labels:  buffer
Spring Boot Mybatis Rw
基于mybatis,springboot开箱即用的读写分离插件
Stars: ✭ 347 (-0.57%)
Mutual labels:  datasource
Pgdiff
Compares the PostgreSQL schema between two databases and generates SQL statements that can be run manually against the second database to make their schemas match.
Stars: ✭ 333 (-4.58%)
Mutual labels:  diffing
React Tabulator
React Tabulator is based on tabulator - a JS table library with many advanced features.
Stars: ✭ 295 (-15.47%)
Mutual labels:  tableview
Safe Buffer
Safer Node.js Buffer API
Stars: ✭ 302 (-13.47%)
Mutual labels:  buffer
Shsegmentedcontroltableview
Both scroll horizontal and vertical for segment scrollview which have a same header. — 类似半糖、美丽说主页与QQ音乐歌曲列表布局效果,实现不同菜单的左右滑动切换,同时支持类似tableview的顶部工具栏悬停(既可以左右滑动,又可以上下滑动)。兼容下拉刷新,上拉加载更多。现已加入swift豪华套餐,使用样例助你快速使用
Stars: ✭ 259 (-25.79%)
Mutual labels:  tableview
Buttercup Core
🎩 The mighty NodeJS password vault
Stars: ✭ 340 (-2.58%)
Mutual labels:  datasource
Tableview
TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
Stars: ✭ 2,928 (+738.97%)
Mutual labels:  tableview
Multidiff
Binary data diffing for multiple objects or streams of data
Stars: ✭ 282 (-19.2%)
Mutual labels:  diffing
Oycountdownmanager
在cell中使用倒计时的处理方法, 全局使用一个NSTimer对象, 支持单列表.多列表.多页面.分页列表使用
Stars: ✭ 317 (-9.17%)
Mutual labels:  tableview
Hisocket
It is a lightweight client socket solution, you can used it in C# project or Unity3d
Stars: ✭ 275 (-21.2%)
Mutual labels:  buffer

Buffer Swift Platform License

Buffer

Swift μ-framework for efficient array diffs, collection observation and data source implementation.

C++11 port here

Installation

cd {PROJECT_ROOT_DIRECTORY}
curl "https://raw.githubusercontent.com/alexdrone/Buffer/master/bin/dist.zip" > dist.zip && unzip dist.zip && rm dist.zip;

Drag Buffer.framework in your project and add it as an embedded binary.

If you use xcodegen add the framework to your project.yml like so:

targets:
  YOUR_APP_TARGET:
    ...
    dependencies:
      - framework: PATH/TO/YOUR/DEPS/Buffer.framework

Installation with CocoaPods/Carthage (deprecated)

If you are using CocoaPods:

Add the following to your Podfile:

pod 'Buffer'

If you are using Carthage:

To install Carthage, run (using Homebrew):

$ brew update
$ brew install carthage

Then add the following line to your Cartfile:

github "alexdrone/Buffer" "master"    

Getting started

Buffer is designed to be very granular and has APIs with very different degrees of abstraction.

Managing a collection with Buffer

You can initialize and use Buffer in the following way.

import Buffer

class MyClass: BufferDelegate {

  lazy var buffer: Buffer<Foo> = {
    // The `sort` and the `filter` closure are optional - they are a convenient way to map the src array.
    let buffer = Buffer(initialArray: self.elements, sort: { $0.bar > $1.bar }, filter: { $0.isBaz })
    buffer.delegate = self
  }()

  var elements: [Foo] = [Foo]() {
    didSet {
      // When the elements are changed the buffer object will compute the difference and trigger
      // the invocation of the delegate methods.
      // The `synchronous` and `completion` arguments are optional.
      self.buffer.update(with: newValues, synchronous: false, completion: nil)
    }
  }


  //These methods will be called when the buffer has changedd.

  public func buffer(willChangeContent buffer: BufferType) {
    //e.g. self.tableView?.beginUpdates()

  }

  public func buffer(didDeleteElementAtIndices buffer: BufferType, indices: [UInt]) {
    //e.g. Remove rows from a tableview
  }

  public func buffer(didInsertElementsAtIndices buffer: BufferType, indices: [UInt]) {
  }

  public func buffer(didChangeContent buffer: BufferType) {
  }

  public func buffer(didChangeElementAtIndex buffer: BufferType, index: UInt) {
  }

  public func buffer(didMoveElement buffer: BufferType, from: UInt, to: UInt) {
  }

  public func buffer(didChangeAllContent buffer: BufferType) {
  }
}

Built-in UITableView and UICollectionView adapter

One of the main use cases for Buffer is probably to apply changes to a TableView or a CollectionView. Buffer provides 2 adapter classes that implement the BufferDelegate protocol and automatically perform the required changes on the target tableview/collectionview when required.

import Buffer

class MyClass: UITableViewController {

  lazy var buffer: Buffer<Foo> = {
    // The `sort` and the `filter` closure are optional - they are convenient way to map the src array.
    let buffer = Buffer(initialArray: self.elements, sort: { $0.bar > $1.bar }, filter: { $0.isBaz })
    buffer.delegate = self
  }()

  var elements: [Foo] = [Foo]() {
    didSet {
      // When the elements are changed the buffer object will compute the difference and trigger
      // the invocation of the delegate methods.
      // The `synchronous` and `completion` arguments are optional.
      self.buffer.update(with: newValues, synchronous: false, completion: nil)
    }
  }

  let adapter: TableViewDiffAdapter<Foo>!

  init() {
    super.init()
    self.adapter = TableViewDiffAdapter(buffer: self.buffer, view: self.tableView)

    // Additionaly you can let the adapter be the datasource for your table view by passing a cell
    // configuration closure to the adpater.
    adapter.useAsDataSource { (tableView, object, indexPath) -> UITableViewCell in
      let cell = tableView.dequeueReusableCellWithIdentifier("MyCell")
	  			cell?.textLabel?.text = object.foo
	  			return cell
    }
  }

}


Component-Oriented TableView

Another convenient way to use Buffer is through the Buffer.TableView class. This abstraction allows for the tableView to reconfigure itself when its state (the elements) change.

import Buffer

class ViewController: UIViewController {

  lazy var tableView: TableView<FooModel> = {
    let tableView = TableView<FooModel>()
    return tableView
  }()

  lazy var elements: [ListItem<FooModel>] = {
    var elements = [ListItem<FooModel>]()
    for _ in 0...100 {
      // AnyListItem wraps the data and the configuration for every row in the tableview.
      let item = ListItem(type: UITableViewCell.self,
                          container: self.tableView,
                          model: FooModel(text: "Foo"))) {
        cell, model in
        cell.textLabel?.text = model.text
      }
      elements.append(item)
    }
    return elements
  }()

  override func viewDidLayoutSubviews() {
    self.tableView.frame = self.view.bounds
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    self.view.addSubview(self.tableView)
    self.tableView.elements = self.elements
  }
}


Check the demo out to learn more about Buffer.

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].