{"id":2875,"url":"https://github.com/FluidGroup/DataSources","last_synced_at":"2025-08-03T12:31:30.398Z","repository":{"id":23986668,"uuid":"99609195","full_name":"FluidGroup/DataSources","owner":"FluidGroup","description":"💾 🔜📱 Type-safe data-driven CollectionView, TableView Framework. (We can also use ASCollectionNode)","archived":false,"fork":false,"pushed_at":"2024-03-17T15:03:29.000Z","size":4732,"stargazers_count":567,"open_issues_count":2,"forks_count":30,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-15T01:19:07.842Z","etag":null,"topics":["collectionview","data-driven","datasource","diff","ios","rxswift","uicollectionview","viewcontroller"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FluidGroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":null,"patreon":"muukii","open_collective":null,"ko_fi":"muukii","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-08-07T18:48:18.000Z","updated_at":"2024-04-24T18:17:39.266Z","dependencies_parsed_at":"2024-01-02T21:17:30.474Z","dependency_job_id":"0afa94d9-72ec-4365-baa6-eddfea24bddc","html_url":"https://github.com/FluidGroup/DataSources","commit_stats":null,"previous_names":["muukii/datasources"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2FDataSources","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2FDataSources/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2FDataSources/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2FDataSources/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FluidGroup","download_url":"https://codeload.github.com/FluidGroup/DataSources/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228543161,"owners_count":17934435,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collectionview","data-driven","datasource","diff","ios","rxswift","uicollectionview","viewcontroller"],"created_at":"2024-01-05T20:16:25.164Z","updated_at":"2024-12-07T00:31:02.307Z","avatar_url":"https://github.com/FluidGroup.png","language":"Swift","readme":"\u003cp align=\"center\"\u003e\n\u003cimg width=656 src=\"logo.png\"\u003e\n\u003c/p\u003e\n\n# DataSources\n💾 🔜📱 Type-safe data-driven List-UI Framework. (We can also use ASCollectionNode)\n\nPartial updates(insert, delete, move) of UICollectionView/UITableView is important things for fancy UI.\u003cbr\u003e\nBut, It's hard that synchronous of data and UI.\u003cbr\u003e\n**DataSources** will solve this problem.\n\n![](https://img.shields.io/badge/Swift-3.1-blue.svg?style=flat)\n[![CI Status](http://img.shields.io/travis/muukii/DataSources.svg?style=flat)](https://travis-ci.org/muukii/DataSources)\n[![Version](https://img.shields.io/cocoapods/v/DataSources.svg?style=flat)](http://cocoapods.org/pods/DataSources)\n[![License](https://img.shields.io/cocoapods/l/DataSources.svg?style=flat)](http://cocoapods.org/pods/DataSources)\n[![Platform](https://img.shields.io/cocoapods/p/DataSources.svg?style=flat)](http://cocoapods.org/pods/DataSources)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmuukii%2FDataSources.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmuukii%2FDataSources?ref=badge_shield)\n\n![](sample.gif)\n\n## Thanks\n\n**Diff-algorithm**\n- Inspired by IGListKit/IGListDiff.\n  - https://github.com/Instagram/IGListKit\n  - https://github.com/lxcid/ListDiff\n  \n## Features\n\n- Data driven update\n  - Data did change, then will display.\n- Partial updates, no more calling `reloadData`\n  - Smooth and Faster.\n  - if the count of changes larger than 300, update with non-animation.\n- Simplified usage\n- We can use different type each section.\n- Type-safe\n  - We can take clearly typed object by IndexPath.\n- Using Adapter-pattern for List-UI\n  - For example, We can also use this for ASCollectionNode of Texture. (Demo app includes it)\n- Reorder by UI operation\n- This library is not supported moving between section.\n\n## Requirements\n\n- Swift 4\n- iOS 9+\n\n## Usage (Example)\n\n### Conform protocol `Diffable`\n\n```swift\npublic protocol Diffable {\n  associatedtype Identifier : Hashable\n  var diffIdentifier: Identifier { get }\n}\n```\n\n```swift\nstruct Model : Diffable {\n\n  var diffIdentifier: String {\n    return id\n  }\n  \n  let id: String\n}\n```\n\n### 🤠 Most Simplified Usage\n\n1. Define `SectionDataController` in ViewController\n\n```swift\nlet collectionView: UICollectionView\n\nlet sectionDataController = SectionDataController\u003cModel, CollectionViewAdapter\u003e(\n  adapter: CollectionViewAdapter(collectionView: self.collectionView),\n  isEqual: { $0.id == $1.id } // If Model has Equatable, you can omit this closure.\n)\n\nvar models: [Model] = [] {\n  didSet {\n    sectionDataController.update(items: items, updateMode: .partial(animated: true), completion: {\n      // Completed update\n    })\n  }\n}\n\nlet dataSource = CollectionViewDataSource(sectionDataController: sectionDataController)\n\ndataSource.cellFactory = { _, collectionView, indexPath, model in\n   let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) as! Cell\n   cell.label.text = model.title\n   return cell\n }\n\ncollectionView.dataSource = dataSource\n```\n\n### 😎 Semi Manual\n\n#### Single-Section (UICollectionView)\n\n1. Define `SectionDataController` in ViewController\n\n```swift\nlet collectionView: UICollectionView\nvar models: [Model]\n\nlet sectionDataController = SectionDataController\u003cModel, CollectionViewAdapter\u003e(\n  adapter: CollectionViewAdapter(collectionView: self.collectionView),\n  isEqual: { $0.id == $1.id } // If Model has Equatable, you can omit this closure.\n)\n```\n\n2. Bind Models to `SectionDataController` in ViewController\n\n```swift\nvar models: [Model] = […] {\n  didSet {\n    sectionDataController.update(items: items, updateMode: .partial(animated: true), completion: {\n      // Completed update\n    })\n  }\n}\n```\n\n3. Implement UICollectionViewDataSource in ViewController\n\n```swift\nfunc numberOfSections(in collectionView: UICollectionView) -\u003e Int {\n  return 1\n}\n\nfunc collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -\u003e Int {\n  return sectionDataController.numberOfItems()\n}\n\nfunc collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -\u003e UICollectionViewCell {\n\n  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) as! Cell\n  let m = sectionDataController.item(for: indexPath)\n  cell.label.text = m.title\n  return cell\n}\n```\n\n#### Multiple-Section (UICollectionView)\n\n1. Define `DataController` in ViewController\n\n```swift\nlet collectionView: UICollectionView\nvar models: [Model]\n\nlet dataController = DataController\u003cCollectionViewAdapter\u003e(adapter: CollectionViewAdapter(collectionView: self.collectionView))\n```\n\n2. Define `Section\u003cT\u003e` in ViewController\n\n```swift\nlet section0 = Section(ModelA.self, isEqual: { $0.id == $1.id })\nlet section1 = Section(ModelB.self, isEqual: { $0.id == $1.id })\n```\n\n3. Add `Section` to `DataController`\n\nOrder of Section will be decided in the order of addition.\n\n```swift\ndataController.add(section: section0) // will be 0 of section\ndataController.add(section: section1) // will be 1 of section\n```\n\n4. Bind Models to DataController\n\n```swift\nvar section0Models: [ModelA] = […] {\n  didSet {\n    dataController.update(\n      in: section0,\n      items: section0Models,\n      updateMode: .partial(animated: true),\n      completion: {\n        \n    })\n  }\n}\n\nvar section1Models: [ModelA] = […] {\n  didSet {\n    dataController.update(\n      in: section1,\n      items: section1Models,\n      updateMode: .partial(animated: true),\n      completion: {\n        \n    })\n  }\n}\n```\n\n5. Implement UICollectionViewDataSource\n\n```swift\nfunc numberOfSections(in collectionView: UICollectionView) -\u003e Int {\n  return dataController.numberOfSections()\n}\n\nfunc collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -\u003e Int {\n  return dataController.numberOfItems(in: section)\n}\n\nfunc collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -\u003e UICollectionViewCell {\n\n  return dataController.item(\n    at: indexPath,    \n    handlers: [\n    .init(section: section0) { (m: ModelA) in\n      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) as! Cell\n      cell.label.text = m.title\n      return cell\n    },\n    .init(section: section1) { (m: ModelB) in\n      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) as! Cell\n      cell.label.text = m.title\n      return cell\n      },\n    ])\n\n  /* Other way\n  switch indexPath.section {\n  case section0:\n    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) as! Cell\n    let m = _dataController.item(at: indexPath, in: section0)\n    cell.label.text = m.title\n    return cell\n  case section1:\n    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) as! Cell\n    let m = _dataController.item(at: indexPath, in: section1)\n    cell.label.text = m.title\n    return cell\n  default:\n    fatalError()\n  }\n   */\n}\n```\n\n## Reorder by UI operation\n\n`SectionDataController` has a snapshot for `List-UI`.\nIt helps that perform batch update List-UI in safety.\n\nBut, the snapshots include side-effects.\nFor example, if we did reorder items of `List-UI` by UI operation.\nIn this time, Items of List-UI is caused differences to the snapshot.\nIt will be caused unnecessary diff.\n\nTherefore when we reorder items, we should operation followings.\n\n0. Reorder items of UI\n1. Call `SectionDataController.reserveMoved(...`\n2. Reorder items of Array\n3. Call `SectionDataController.update(items: [T]..`\n\n# Demo Application\n\nThis repository include Demo-Application.\nYou can touch DataSources.\n\n1. Clone repository.\n\n```\n$ git clone https://github.com/muukii/DataSources.git\n$ cd DataSources\n$ pod install\n```\n\n2. Open xcworkspace\n3. Run `DataSourcesDemo` on iPhone Simulator.\n\n# Author\n\nmuukii, m@muukii.me, https://muukii.me/\n\n# License\n\n**DataSources** is available under the MIT license. See the LICENSE file for more info.\n\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmuukii%2FDataSources.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmuukii%2FDataSources?ref=badge_large)\n","funding_links":["https://patreon.com/muukii","https://ko-fi.com/muukii"],"categories":["UI"],"sub_categories":["Table View / Collection View"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFluidGroup%2FDataSources","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFluidGroup%2FDataSources","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFluidGroup%2FDataSources/lists"}