diff --git a/README.md b/README.md index 5c0ed26..e3d39ae 100644 --- a/README.md +++ b/README.md @@ -751,51 +751,53 @@ public protocol Deallocatable: class { ReactiveKit provides conformance to this protocol for `NSObject` and its subclasses out of the box. -Protocol `BindingExecutionContextProvider` provides the execution context on which the object can be updated. Execution context is just a wrapper over dispatch queue or a thread. You can see how it is implemented [here](https://github.com/ReactiveKit/ReactiveKit/blob/master/Sources/ExecutionContext.swift). +How do you conform to `Deallocatable`? The simplest way is conforming to `DisposeBagProvider` instead. ```swift -public protocol BindingExecutionContextProvider { +/// A type that provides a dispose bag. +/// `DisposeBagProvider` conforms to `Deallocatable` out of the box. +public protocol DisposeBagProvider: Deallocatable { - /// An execution context used to deliver binding events. - var bindingExecutionContext: ExecutionContext { get } + /// A `DisposeBag` that can be used to dispose observations and bindings. + var bag: DisposeBag { get } } -``` -`NSObject` conforms to this protocol by providing `.immediateOnMain` context. - -```swift -extension NSObject: BindingExecutionContextProvider { +extension DisposeBagProvider { - public var bindingExecutionContext: ExecutionContext { - return .immediateOnMain + public var deallocated: SafeSignal { + return bag.deallocated } } ``` -`ExecutionContext.immediateOnMain` executes synchronously if the current thread is main, otherwise it makes asynchronous dispatch to main queue. - -If your type is a subclass of `NSObject`, you can always override `bindingExecutionContext` property to provide another context. On the other hand, if your type is not a subclass of `NSObject` all you need to do is conform to `BindingExecutionContextProvider`. +As you can see, `DisposeBagProvider` inherits `Deallocatable` and implements is by taking the deallocated signal from the bag. So all that you need to do is provide a `bag` property. -How do you conform to `Deallocatable`? The simplest way is conforming to `DisposeBagProvider` instead. +`BindingExecutionContextProvider` protocol provides the execution context in which the object should be updated. Execution context is just a wrapper over a dispatch queue or a thread. You can see how it is implemented [here](https://github.com/ReactiveKit/ReactiveKit/blob/master/Sources/ExecutionContext.swift). ```swift -/// A type that provides a dispose bag. -/// `DisposeBagProvider` conforms to `Deallocatable` out of the box. -public protocol DisposeBagProvider: Deallocatable { +public protocol BindingExecutionContextProvider { - /// A `DisposeBag` that can be used to dispose observations and bindings. - var bag: DisposeBag { get } + /// An execution context used to deliver binding events. + var bindingExecutionContext: ExecutionContext { get } } +``` -extension DisposeBagProvider { +> Bond framework provides `BindingExecutionContextProvider` conformance to various UIKit objects so they can be seamlessly bound to while ensuring the main thread. - public var deallocated: SafeSignal { - return bag.deallocated +You can conform to this protocol by providing execution context. + +```swift +extension MyViewModel: BindingExecutionContextProvider { + + public var bindingExecutionContext: ExecutionContext { + return .immediateOnMain } } ``` -As you can see, `DisposeBagProvider` inherits `Deallocatable` and implements is by taking the deallocated signal from the bag. So all that you need to do is provide a `bag` property. +`ExecutionContext.immediateOnMain` executes synchronously if the current thread is main, otherwise it makes asynchronous dispatch to main queue. If you want to bind on background queue, you can return `.background` instead. + +> Note that updating UIKit or AppKit objects must always happen from the main thread or queue. Now we can peek into the binding implementation. diff --git a/ReactiveKit.podspec b/ReactiveKit.podspec index 57bfabe..21e4c7d 100644 --- a/ReactiveKit.podspec +++ b/ReactiveKit.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = "ReactiveKit" - s.version = "3.5.0" + s.version = "3.5.1" 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" => "srdan.rasic@gmail.com" } - s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v3.5.0" } + s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v3.5.1" } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.9' diff --git a/ReactiveKit/Info.plist b/ReactiveKit/Info.plist index 2bf762f..8499977 100644 --- a/ReactiveKit/Info.plist +++ b/ReactiveKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.5.0 + 3.5.1 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/Bindable.swift b/Sources/Bindable.swift index 9ef7cd9..2a724f8 100644 --- a/Sources/Bindable.swift +++ b/Sources/Bindable.swift @@ -115,18 +115,8 @@ extension SignalProtocol where Error == NoError { } /// Provides an execution context used to deliver binding events. -/// -/// `NSObject` conforms to this protocol be providing `ImmediateOnMainExecutionContext` -/// as binding execution context. Specific subclasses can override the context if needed. public protocol BindingExecutionContextProvider { /// An execution context used to deliver binding events. var bindingExecutionContext: ExecutionContext { get } } - -extension NSObject: BindingExecutionContextProvider { - - public var bindingExecutionContext: ExecutionContext { - return .immediateOnMain - } -}