Coder Social home page Coder Social logo

mitchellporter / consistencymanager-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from plivesey/consistencymanager

0.0 0.0 0.0 1.43 MB

A library that manages consistency of immutable models

Home Page: https://linkedin.github.io/ConsistencyManager-iOS/

License: Apache License 2.0

Ruby 0.45% Objective-C 0.82% Swift 88.67% Shell 10.06%

consistencymanager-ios's Introduction

Overview

Build Status codecov GitHub release Platforms

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/linkedin/RocketData

Documentation: https://linkedin.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://linkedin.github.io/ConsistencyManager-iOS

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 3.

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

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.

consistencymanager-ios's People

Contributors

albinekcom avatar asowers1 avatar jdhealy avatar plivesey avatar rishabhtayal avatar satanwoo 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.