-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
Deallocatable
and BindingExecutionContextProvider
. Impl…
…ement `bind(to:)`. Improve documentation of various classes.
- Loading branch information
1 parent
125d52d
commit e781e1d
Showing
9 changed files
with
245 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "ReactiveKit" | ||
s.version = "3.3.1" | ||
s.version = "3.4.0" | ||
s.summary = "A Swift Reactive Programming Framework" | ||
s.description = "ReactiveKit is a Swift framework for reactive and functional reactive programming." | ||
s.homepage = "https://github.com/ReactiveKit/ReactiveKit" | ||
s.license = 'MIT' | ||
s.author = { "Srdan Rasic" => "[email protected]" } | ||
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v3.3.1" } | ||
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v3.4.0" } | ||
|
||
s.ios.deployment_target = '8.0' | ||
s.osx.deployment_target = '10.9' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// Deallocatable.swift | ||
// ReactiveKit | ||
// | ||
// Created by Srdan Rasic on 17/03/2017. | ||
// Copyright © 2017 Srdan Rasic. All rights reserved. | ||
// | ||
|
||
/// A type that notifies about its own deallocation. | ||
/// | ||
/// `Deallocatable` can be used as a binding target. For example, | ||
/// instead of observing a signal, one can bind it to a `Deallocatable`. | ||
/// | ||
/// class View: Deallocatable { ... } | ||
/// | ||
/// let view: View = ... | ||
/// let signal: SafeSignal<Int> = ... | ||
/// | ||
/// signal.bind(to: view) { view, number in | ||
/// view.display(number) | ||
/// } | ||
public protocol Deallocatable: class { | ||
|
||
/// A signal that fires `completed` event when the receiver is deallocated. | ||
var deallocated: SafeSignal<Void> { get } | ||
} | ||
|
||
/// A type that provides a dispose bag. | ||
/// `DisposeBagProvider` conforms to `Deallocatable` out of the box. | ||
public protocol DisposeBagProvider: Deallocatable { | ||
|
||
/// A `DisposeBag` that can be used to dispose observations and bindings. | ||
var bag: DisposeBag { get } | ||
} | ||
|
||
extension DisposeBagProvider { | ||
|
||
/// A signal that fires `completed` event when the receiver is deallocated. | ||
public var deallocated: SafeSignal<Void> { | ||
return bag.deallocated | ||
} | ||
} | ||
|
||
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) | ||
|
||
import ObjectiveC.runtime | ||
|
||
extension NSObject: DisposeBagProvider { | ||
|
||
private struct AssociatedKeys { | ||
static var DisposeBagKey = "DisposeBagKey" | ||
} | ||
|
||
public var bag: DisposeBag { | ||
if let disposeBag = objc_getAssociatedObject(self, &NSObject.AssociatedKeys.DisposeBagKey) { | ||
return disposeBag as! DisposeBag | ||
} else { | ||
let disposeBag = DisposeBag() | ||
objc_setAssociatedObject(self, &NSObject.AssociatedKeys.DisposeBagKey, disposeBag, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) | ||
return disposeBag | ||
} | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.