Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Verkoeyen committed Dec 7, 2016
2 parents 09dabc8 + 825ffa9 commit e95f516
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 141 deletions.
4 changes: 2 additions & 2 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module: IndefiniteObservable
module_version: 1.0.0
module_version: 2.0.0
sdk: iphonesimulator
xcodebuild_arguments:
- -workspace
- IndefiniteObservable.xcworkspace
- -scheme
- IndefiniteObservable
github_url: https://github.com/material-motion/indefinite-observable-swift
github_file_prefix: https://github.com/material-motion/indefinite-observable-swift/tree/v1.0.0
github_file_prefix: https://github.com/material-motion/indefinite-observable-swift/tree/v2.0.0
69 changes: 69 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
# 2.0.0

IndefiniteObservable now supports novel Observer implementations using a genericized Observer type.

## Breaking changes

- Removed `AnyObserver`.
- Renamed `noUnsubscription` to `noopUnsubscription`.

## New features

- `IndefiniteObservable` now requires a generic Observer type, enabling the creation of custom
observers with channels other than `next`.

## Source changes

* [Make the shape of the default Observer have a value and next function.](https://github.com/material-motion/indefinite-observable-swift/commit/a78e255c60b2ba855d16333216a78ed6147389ac) (Jeff Verkoeyen)
* [Make IndefiniteObservable observer-agnostic.](https://github.com/material-motion/indefinite-observable-swift/commit/8c30e9a2517211c6d7a36b9c5e129d2dd3ee5dda) (Jeff Verkoeyen)
* [Cleaned up and added some additional unit tests](https://github.com/material-motion/indefinite-observable-swift/commit/0a630845641602724853ccce7279331adb87368f) (Jeff Verkoeyen)
* [Remove unnecessary UpstreamSubscription.](https://github.com/material-motion/indefinite-observable-swift/commit/0914e5d866f30f756f9d5799cac6d55572190567) (Jeff Verkoeyen)
* [Set next in the ValueObserver wrather than wrap it.](https://github.com/material-motion/indefinite-observable-swift/commit/ec6d4b1410ee46ce0a46854fb14bfb9ddc0074fa) (Jeff Verkoeyen)
* [Make IndefiniteObservable final so that it can't be subclassed.](https://github.com/material-motion/indefinite-observable-swift/commit/fd5869de6aeb69add9db5f820064f604cb4d8e78) (Jeff Verkoeyen)
* [Rename noUnsubscription to noopUnsubscription.](https://github.com/material-motion/indefinite-observable-swift/commit/7ff94398942bdcbc91230330e4541ae8e5bef296) (Jeff Verkoeyen)
* [Remove the unused Observer type.](https://github.com/material-motion/indefinite-observable-swift/commit/bad9ca6f410d5ff6d9ee9b3fb142b7c120e15b6a) (Jeff Verkoeyen)
* [Rename AnyObserver to ValueObserver.](https://github.com/material-motion/indefinite-observable-swift/commit/b6a280e41ee9410e5e14c9d3368fb24b60ad1577) (Jeff Verkoeyen)

## API changes

Auto-generated by running:

apidiff origin/stable release-candidate swift IndefiniteObservable.xcworkspace IndefiniteObservable

## noUnsubscription

*renamed* global var: `noUnsubscription` → `noopUnsubscription`

## Observer

*new* var: `next` in `Observer`

*removed* method: `next(_:)` in `Observer`

## AnyObserver

*removed* class: `AnyObserver`

*removed* method: `next(_:)` in `AnyObserver`

## IndefiniteObservable

*new* method: `subscribe(observer:)` in `IndefiniteObservable`

*removed* method: `subscribe(next:)` in `IndefiniteObservable`

*modified* class: `IndefiniteObservable`

| Type of change: | key.doc.declaration |
|---|---|
| From: | `open class IndefiniteObservable<T>` |
| To: | `open class IndefiniteObservable<O : Observer>` |

## Non-source changes

* [Automatic changelog preparation for release.](https://github.com/material-motion/indefinite-observable-swift/commit/f1f6e215013af5927dcda4e6a305714df6745732) (Jeff Verkoeyen)
* [Better podspec description.](https://github.com/material-motion/indefinite-observable-swift/commit/11df6b0e78930daed9503f5b119d59e4d4316d2f) (Jeff Verkoeyen)
* [Fix typo in README.md guides.](https://github.com/material-motion/indefinite-observable-swift/commit/8f762cdea31b76d9fb1ccb77547a4ffbdc585e12) (Jeff Verkoeyen)
* [Undo the previous change.](https://github.com/material-motion/indefinite-observable-swift/commit/ad148e61004f6aaf55527765067fe72297e1d362) (Jeff Verkoeyen)
* [Poke the travis build.](https://github.com/material-motion/indefinite-observable-swift/commit/6e0168c3f2f475c8a60aee7e8173d56af738cdfe) (Jeff Verkoeyen)

# 1.0.0

Stable release of `IndefiniteObservable`.
Expand Down
4 changes: 2 additions & 2 deletions IndefiniteObservable.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "IndefiniteObservable"
s.summary = "IndefiniteObservable.swift"
s.version = "1.0.0"
s.summary = "IndefiniteObservable is a minimal implementation of Observable with no concept of completion or failure."
s.version = "2.0.0"
s.authors = "The Material Motion Authors"
s.license = "Apache 2.0"
s.homepage = "https://github.com/material-motion/indefinite-observable-swift"
Expand Down
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PODS:
- CatalogByConvention (2.0.0)
- IndefiniteObservable/examples (1.0.0):
- IndefiniteObservable/examples (2.0.0):
- IndefiniteObservable/lib
- IndefiniteObservable/lib (1.0.0)
- IndefiniteObservable/lib (2.0.0)

DEPENDENCIES:
- CatalogByConvention
Expand All @@ -15,7 +15,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
CatalogByConvention: be55c2263132e4f9f59299ac8a528ee8715b3275
IndefiniteObservable: b90809f2fa025e37124c14681192bc441b128625
IndefiniteObservable: 66776cf0f5929a5a260bf04d340bfb0a7087d56f

PODFILE CHECKSUM: 3e4cdba95901e07a289159f0c5a8b830ecb1a5c8

Expand Down
60 changes: 42 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,42 @@ commands:

# Guides

1. [How to make an observable](#how-to-make-an-observable)
1. [How to create a synchronous stream](#how-to-create-a-synchronous-stream)
2. [How to create an asynchronous stream using blocks](#how-to-create-an-asynchronous-stream-using-blocks)
3. [How to subscribe to a stream](#how-to-subscribe-to-a-stream)
4. [How to unsubscribe from a stream](#how-to-unsubscribe-from-a-stream)
5. [How to create an synchronous stream using objects](#how-to-create-an-synchronous-stream-using-objects)
1. [How to create an asynchronous stream using blocks](#how-to-create-an-asynchronous-stream-using-blocks)
1. [How to subscribe to a stream](#how-to-subscribe-to-a-stream)
1. [How to unsubscribe from a stream](#how-to-unsubscribe-from-a-stream)
1. [How to create an synchronous stream using objects](#how-to-create-an-synchronous-stream-using-objects)

## How to make an observable

In this example we'll make the simplest possible observable type: a value observable. We will use
this concrete type in all of the following guides.

```swift
final class ValueObserver<T>: Observer {
typealias Value = T

init(_ next: @escaping (T) -> Void) {
self.next = next
}

let next: (T) -> Void
}

final class ValueObservable<T>: IndefiniteObservable<ValueObserver<T>> {
func subscribe(_ next: @escaping (T) -> Void) -> Subscription {
return super.subscribe(observer: ValueObserver(next))
}
}
```

## How to create a synchronous stream

```swift
let observable = IndefiniteObservable<<#ValueType#>> { observer in
let observable = ValueObservable<<#ValueType#>> { observer in
observer.next(<#value#>)
return noUnsubscription
return noopUnsubscription
}
```

Expand All @@ -75,7 +99,7 @@ If you have an API that provides a block-based mechanism for registering observe
create an asynchronous stream in place like so:

```swift
let observable = IndefiniteObservable<<#ValueType#>> { observer in
let observable = ValueObservable<<#ValueType#>> { observer in
let someToken = registerSomeCallback { callbackValue in
observer.next(callbackValue)
}
Expand Down Expand Up @@ -117,7 +141,7 @@ need to create a `Producer` class. A `Producer` listens for events with an event
class DragProducer: Subscription {
typealias Value = (state: UIGestureRecognizerState, location: CGPoint)

init(subscribedTo gesture: UIPanGestureRecognizer, observer: AnyObserver<Value>) {
init(subscribedTo gesture: UIPanGestureRecognizer, observer: ValueObserver<Value>) {
self.gesture = gesture
self.observer = observer

Expand All @@ -141,14 +165,14 @@ class DragProducer: Subscription {
}

var gesture: (UIPanGestureRecognizer)?
let observer: AnyObserver<Value>
let observer: ValueObserver<Value>
}

let pan = UIPanGestureRecognizer()
view.addGestureRecognizer(pan)

let dragStream = IndefiniteObservable<DragProducer.Value> { observer in
return DragProducer(subscribedTo: pan, observer: observer).subscription
let dragStream = ValueObservable<DragProducer.Value> { observer in
return DragProducer(subscribedTo: pan, observer: observer).unsubscribe
}
let subscription = dragStream.subscribe {
dump($0.state)
Expand All @@ -175,22 +199,22 @@ class DragProducer: Subscription {

### Step 3: Implement the initializer

Your initializer must accept and store an `AnyObserver<Value>` instance.
Your initializer must accept and store an `ValueObserver<Value>` instance.

```swift
init(subscribedTo gesture: UIPanGestureRecognizer, observer: AnyObserver<Value>) {
init(subscribedTo gesture: UIPanGestureRecognizer, observer: ValueObserver<Value>) {
self.gesture = gesture
self.observer = observer
}

var gesture: (UIPanGestureRecognizer)?
let observer: AnyObserver<Value>
let observer: ValueObserver<Value>
```

### Step 4: Connect to the event source and send values to the observer

```swift
init(subscribedTo gesture: UIPanGestureRecognizer, observer: AnyObserver<Value>) {
init(subscribedTo gesture: UIPanGestureRecognizer, observer: ValueObserver<Value>) {
...

gesture.addTarget(self, action: #selector(didPan))
Expand Down Expand Up @@ -221,7 +245,7 @@ You are responsible for disconnecting from and releasing any resources here.
It often is helpful to provide the observer with the current state on registration.

```swift
init(subscribedTo gesture: UIPanGestureRecognizer, observer: AnyObserver<Value>) {
init(subscribedTo gesture: UIPanGestureRecognizer, observer: ValueObserver<Value>) {
...

// Populate the observer with the current gesture state.
Expand All @@ -232,8 +256,8 @@ It often is helpful to provide the observer with the current state on registrati
### Step 7: Observe the producer

```swift
let dragStream = IndefiniteObservable<DragProducer.Value> { observer in
return DragProducer(subscribedTo: pan, observer: observer).subscription
let dragStream = ValueObservable<DragProducer.Value> { observer in
return DragProducer(subscribedTo: pan, observer: observer).unsubscribe
}
let subscription = dragStream.subscribe {
dump($0)
Expand Down
14 changes: 7 additions & 7 deletions examples/DelegateObservableExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import IndefiniteObservable
class DragProducer: Subscription {
typealias Value = (state: UIGestureRecognizerState, location: CGPoint)

init(subscribedTo gesture: UIPanGestureRecognizer, observer: AnyObserver<Value>) {
init(subscribedTo gesture: UIPanGestureRecognizer, observer: ValueObserver<Value>) {
self.gesture = gesture
self.observer = observer

Expand All @@ -48,7 +48,7 @@ class DragProducer: Subscription {
}

var gesture: (UIPanGestureRecognizer)?
let observer: AnyObserver<Value>
let observer: ValueObserver<Value>
}

public class DelegateObservableExampleViewController: UIViewController {
Expand All @@ -67,20 +67,20 @@ public class DelegateObservableExampleViewController: UIViewController {
let pan = UIPanGestureRecognizer()
view.addGestureRecognizer(pan)

let dragStream = IndefiniteObservable<DragProducer.Value> { observer in
let dragStream = IndefiniteObservable { observer in
return DragProducer(subscribedTo: pan, observer: observer).unsubscribe
}

// Must hold a reference to the subscription, otherwise the stream will be deallocated when the
// subscription goes out of scope.
subscriptions.append(dragStream.subscribe {
subscriptions.append(dragStream.subscribe(observer: ValueObserver {
if $0.state == .began || $0.state == .changed {
targetView.layer.position = $0.location
}
})
}))

subscriptions.append(dragStream.subscribe {
subscriptions.append(dragStream.subscribe(observer: ValueObserver {
print($0.state.rawValue)
})
}))
}
}
Loading

0 comments on commit e95f516

Please sign in to comment.