plivesey/ConsistencyManager
소개
불변 모델의 일관성을 관리하는 라이브러리입니다.
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalOverview
This library provides a way of keeping immutable models consistent. First, listeners listen to an immutable model. Whenever this model (or any child model) is updated, the Consistency Manager will generate a new model and notify its listeners.
Rocket Data
If you are interested in this project, you may want to consider using Rocket Data which provides a higher level API for the Consistency Manager. It implements caching, collection support, and conflict resolution. It's the recommended way for consuming the Consistency Manager.
GitHub: https://github.com/plivesey/RocketData
Documentation: https://plivesey.github.io/RocketData
Installation
pod 'ConsistencyManager'
Motivation
Immutable models have many advantages including thread-safety, performance, and more functional and understandable code. However, many applications need to be able to update their models, and these models are often shared across different screens. Since the models are immutable, you always need to create new models for changes. Then, you need to propagate these changes to all the screens rendering this model. The Consistency Manager provides a pub-sub API and automatically regenerates new models for listeners.
How It Works
Immutable models can be visualized as trees. Each model has fields representing data (strings, ints, etc.) and pointers to other immutable models. Each model also may have an id to uniquely identify themselves. For instance, a messaging application could have these two models:

In the application, two view controllers would register with the Consistency Manager that they are listening on these models.
// In each UIViewController
ConsistencyManager.sharedInstance.listenForUpdates(self)
Later in the application, some source, like a network request, push notification, or user action, indicates that a person with id = 12 has come online. The application can then create a new person model which looks like this:

Then, the application would update this model in the consistency manager.
ConsistencyManager.sharedInstance.updateWithNewModel(personModel)
The Consistency Manager finds that two models, Message and Contacts, need updating and creates new copies of these models with the updated Person model:

The Consistency Manager then delivers the updated models to the subscribed listeners (view controllers in this case) via delegate callbacks. The view controller simply needs to set the new data and refresh its view.
Docs
To get started, you should take a look at the docs:
https://plivesey.github.io/ConsistencyManager
Swift Version
We are currently not maintaining separate branches for different Swift versions. You can use an older and stable version of the Consistency Manager for older versions of Swift though. HEAD currently supports Swift 4.2.
| Swift Version | Consistency Manager Version |
|---|---|
| 1 | Not supported |
| 2.0 - 2.1 | 2.x.x (untested) |
| 2.2 - 2.3 | 2.x.x |
| 3 (Easy migration API) | 3.x.x |
| 3 (Better API) | 4.x.x |
| 4 | 5.1.1+ |
| 4.2 | 7.0.0 |
NOTE: If you are migrating to Swift 3, consider using version 3.0.0 first, then migrating to 4.x.x. 3.0.0 migrates the code to the new syntax without making any API changes. 4.x.x introduces a better API which is more consistent with the new Swift 3 API guidelines.
관련 프로젝트 살펴보기
불러오는 중…