Giter VIP home page Giter VIP logo

loop's Introduction

ReactiveCocoa

Reactive extensions to Cocoa frameworks, built on top of ReactiveSwift.

Join the ReactiveSwift Slack community.


Carthage compatible CocoaPods compatible SwiftPM compatible GitHub release Swift 5.1 platforms

⚠️ Looking for the Objective-C API?

🎉 Migrating from RAC 4.x?

🚄 Release Roadmap

What is ReactiveSwift?

ReactiveSwift offers composable, declarative and flexible primitives that are built around the grand concept of streams of values over time. These primitives can be used to uniformly represent common Cocoa and generic programming patterns that are fundamentally an act of observation.

For more information about the core primitives, see ReactiveSwift.

What is ReactiveCocoa?

ReactiveCocoa wraps various aspects of Cocoa frameworks with the declarative ReactiveSwift primitives.

  1. UI Bindings

    UI components expose BindingTargets, which accept bindings from any kind of streams of values via the <~ operator.

    // Bind the `name` property of `person` to the text value of an `UILabel`.
    nameLabel.reactive.text <~ person.name

    Note: You'll need to import ReactiveSwift as well to make use of the <~ operator.

  2. Controls and User Interactions

    Interactive UI components expose Signals for control events and updates in the control value upon user interactions.

    A selected set of controls provide a convenience, expressive binding API for Actions.

    // Update `allowsCookies` whenever the toggle is flipped.
    preferences.allowsCookies <~ toggle.reactive.isOnValues
    
    // Compute live character counts from the continuous stream of user initiated
    // changes in the text.
    textField.reactive.continuousTextValues.map { $0.characters.count }
    
    // Trigger `commit` whenever the button is pressed.
    button.reactive.pressed = CocoaAction(viewModel.commit)
  3. Declarative Objective-C Dynamism

    Create signals that are sourced by intercepting Objective-C objects, e.g. method call interception and object deinitialization.

    // Notify after every time `viewWillAppear(_:)` is called.
    let appearing = viewController.reactive.trigger(for: #selector(UIViewController.viewWillAppear(_:)))
    
    // Observe the lifetime of `object`.
    object.reactive.lifetime.ended.observeCompleted(doCleanup)
  4. Expressive, Safe Key Path Observation

    Establish key-value observations in the form of SignalProducers and DynamicPropertys, and enjoy the inherited composability.

    // A producer that sends the current value of `keyPath`, followed by
    // subsequent changes.
    //
    // Terminate the KVO observation if the lifetime of `self` ends.
    let producer = object.reactive.producer(forKeyPath: #keyPath(key))
    	.take(during: self.reactive.lifetime)
    
    // A parameterized property that represents the supplied key path of the
    // wrapped object. It holds a weak reference to the wrapped object.
    let property = DynamicProperty<String>(object: person,
                                           keyPath: #keyPath(person.name))

But there are still more to be discovered and introduced. Read our in-code documentations and release notes to find out more.

Getting started

ReactiveCocoa supports macOS 10.9+, iOS 8.0+, watchOS 2.0+, and tvOS 9.0+.

Carthage

If you use Carthage to manage your dependencies, simply add ReactiveCocoa to your Cartfile:

github "ReactiveCocoa/ReactiveCocoa" ~> 10.1

If you use Carthage to build your dependencies, make sure you have added ReactiveCocoa.framework and ReactiveSwift.framework to the "Linked Frameworks and Libraries" section of your target, and have included them in your Carthage framework copying build phase.

CocoaPods

If you use CocoaPods to manage your dependencies, simply add ReactiveCocoa to your Podfile:

pod 'ReactiveCocoa', '~> 10.1'

Swift Package Manager

If you use Swift Package Manager, simply add ReactiveCocoa as a dependency of your package in Package.swift:

.package(url: "https://github.com/ReactiveCocoa/ReactiveCocoa.git", branch: "master")

Git submodule

  1. Add the ReactiveCocoa repository as a submodule of your application’s repository.
  2. Run git submodule update --init --recursive from within the ReactiveCocoa folder.
  3. Drag and drop ReactiveCocoa.xcodeproj and Carthage/Checkouts/ReactiveSwift/ReactiveSwift.xcodeproj into your application’s Xcode project or workspace.
  4. On the “General” tab of your application target’s settings, add ReactiveCocoa.framework and ReactiveSwift.framework to the “Embedded Binaries” section.
  5. If your application target does not contain Swift code at all, you should also set the EMBEDDED_CONTENT_CONTAINS_SWIFT build setting to “Yes”.

Have a question?

If you need any help, please visit our GitHub issues or Stack Overflow. Feel free to file an issue if you do not manage to find any solution from the archives.

Release Roadmap

Current Stable Release:
GitHub release

In Development

Plan of Record

ABI stability release

ReactiveCocoa is expected to declare library ABI stability when Swift rolls out resilience support in Swift 5. Until then, ReactiveCocoa will incrementally adopt new language features.

loop's People

Contributors

andersio avatar chitrakotwani avatar daniel1of1 avatar dmcrodrigues avatar freak4pc avatar ilyapuchka avatar konrad-em avatar mluisbrown avatar ole avatar p4checo avatar ruiaaperes avatar sergdort avatar zzcgumn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loop's Issues

Add events to the feedbacks

Resurrecting old proposal from @inamiy babylonhealth/ReactiveFeedback#41

This is an additive change to add Optional<Event> argument in Feedback so that unnecessary intermediate states will no longer be required.

Event-driven feedback will be useful for following scenarios, without needing to add a new state and then transit (and transit back again):

  • Logging
  • Analytics
  • Routing
  • Image loader (but not managing its internal states)

This is a change from Moore model to (kind of) Mealy model as discussed in babylonhealth/ReactiveFeedback#32 (review) .

Please note that reducer and feedback are still in sequence, not parallel.

Also, please note that Optional<Event> is used here as a workaround since it requires more breaking changes to minimize into non-optional Event.

Remove Old Feedback signature in favour of new.

At this point I do not see a value having two sightly different implementation of the same thing.

I proposing to remove old system operator that takes scheduler in favour of new queue-drain event processing.

FeedbackLoop.Feedback -> Feedback

SwiftUI integration

Loop may offer in-built SwiftUI integration on Apple platforms without creating an extra "LoopUI" package.

Loop only needs to provide standard data funnels to connect feedback loops with SwiftUI, and has no involvement in UI concerns except for the two characters in import SwiftUI. Everything else is SwiftUI's declarative UI realm (data to virtual DOM, vDOM to native view, etc). That is in contrast to our UIKit sibling ReactiveCocoa, which is a heavy UI-focused library that (1) attempted to solve AppKit/UIKit reactive programming at a micro level (KVO-like property bindings), and (2) wraps parts of Objective-C dynamism into friendly Swift APIs.

Since SwiftUI is shipped with the system, no friction is incurred for dependency management on users' end. All these collectively makes it perfect for Loop to offer straightly the said utilities.

Such integration should be excluded from Linux builds.

Concepts

Concepts are built upon the implicit behavior of DynamicProperty, which serves as a clue for SwiftUI runtime to look inside the property wrapper, so as to pick up embedded special wrappers like @State, @ObservedObject and @Environment.

This enables us to build custom property wrappers that provide simple dev experience, while hiding the heavy lifting of bridging feedback loops to SwiftUI world.

Direct state binding like @ObservedObject:

Bound view pseudo code
typealias WeatherStore = Store<WeatherState, WeatherAction>

struct WeatherView: View {
    @WeatherStore.Binding
    var state: WeatherState

    init(store: WeatherStore) {
      _state = store.binding()
    }

    var body: some Body {
        VStack {
            Spacer()

            Text("Current temperature: \(state.temperature)")
                + Text(" \(state.unit)").font(.system(size: 10.0)).baselineOffset(7.0)
            Spacer()
            Button()
                action: { self.$state.perform(.refresh) }
                label: { Text("Refresh 🔄") }

            Spacer()
    }
}

SwiftUI environment injected state bindings

Note: Unlike @State and @ObservedObject, it hasn't been tested whether @EnvironmentObject would work.

Bound view pseudo code
typealias WeatherStore = Store<WeatherState, WeatherAction>

struct WeatherView: View {
    @WeatherStore.EnvironmentBinding
    var state: WeatherStore.State

    var body: some Body {
        VStack {
            Spacer()

            Text("Current temperature: \(state.temperature)")
                + Text(" \(state.unit)").font(.system(size: 10.0)).baselineOffset(7.0)
            Spacer()
            Button()
                action: { self.$state.perform(.refresh) }
                label: { Text("Refresh 🔄") }

            Spacer()
    }
}
Parent view pseudo code
typealias WeatherStore = Store<WeatherState, WeatherAction>
let weatherStore = WeatherStore()

struct ContentView: View {
    var body: some Body {
        WeatherView()
            .environmentObject(weatherStore)
    }
}

Partial store

Already supported via Store.view(value:event:). e.g. injecting via @EnvironmentBinding a partial store that exposes only state & events related to radar images.

typealias WeatherStore = Store<WeatherState, WeatherAction>
let weatherStore = WeatherStore()

struct ContentView: View {
    var body: some Body {
        RadarView()
            .environmentObject(
                weatherStore.view
                    value: \WeatherState.radarImages
                    event: WeatherAction.radar
            )
    }
}

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.