Skip to content

Commit

Permalink
Adapts UI extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzaher committed Aug 13, 2017
1 parent 4b9ca23 commit ac8240d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 26 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## Master

## [0.3.1](https://github.com/kzaher/RxFeedback/releases/tag/0.3.1)

* Adapts UI extensions.

## [0.3.0](https://github.com/kzaher/RxFeedback/releases/tag/0.3.0)

* Improves reentrancy properties.
* Adds `ObservableSchedulerContext` and additional `system` operator overload that enables passing of scheduler to feedback loops to improve cancellation guarantees.
* Improves built in feedback loops with additional cancellation guarantees.
* Receiving stale events by using built-in feedback loops shouldn't be possible anymore.
* Deprecates feedback loops that don't use scheduler argument.
* Deprecates feedback loops that don't use scheduler argument.
16 changes: 8 additions & 8 deletions Examples/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class CounterViewController: UIViewController {
Observable.system(
initialState: 0,
reduce: { (state, event) -> State in
switch event {
case .increment:
return state + 1
case .decrement:
return state - 1
}
},
switch event {
case .increment:
return state + 1
case .decrement:
return state - 1
}
},
scheduler: MainScheduler.instance,
feedback:
scheduledFeedback:
// UI is user feedback
UI.bind(self) { me, state -> UI.Bindings<Event> in
let subscriptions = [
Expand Down
16 changes: 8 additions & 8 deletions Examples/PlayCatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PlayCatchViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let bindUI: (Observable<State>) -> Observable<Event> = UI.bind(self) { me, state in
let bindUI: (ObservableSchedulerContext<State>) -> Observable<Event> = UI.bind(self) { me, state in
let subscriptions = [
state.map { $0.myStateOfMind }.bind(to: me.myLabel!.rx.text),
state.map { $0.machineStateOfMind }.bind(to: me.machinesLabel!.rx.text),
Expand All @@ -48,14 +48,14 @@ class PlayCatchViewController: UIViewController {
initialState: State.humanHasIt,
reduce: { (state: State, event: Event) -> State in
switch event {
case .throwToMachine:
return .machineHasIt
case .throwToHuman:
return .humanHasIt
}
},
case .throwToMachine:
return .machineHasIt
case .throwToHuman:
return .humanHasIt
}
},
scheduler: MainScheduler.instance,
feedback:
scheduledFeedback:
// UI is human feedback
bindUI,
// NoUI, machine feedback
Expand Down
2 changes: 1 addition & 1 deletion RxFeedback.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RxFeedback"
s.version = "0.3.0"
s.version = "0.3.1"
s.summary = "Simplest architecture for RxSwift. State + feedback loops."
s.description = <<-DESC
Simplest architecture for RxSwift. State + feedback loops.
Expand Down
20 changes: 16 additions & 4 deletions RxFeedback.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
52D6D9871BEFF229002C0205 /* RxFeedback.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* RxFeedback.framework */; };
C8047ABC1F41099F0089721B /* CHANGELOG.md in Sources */ = {isa = PBXBuildFile; fileRef = C8047ABB1F41099F0089721B /* CHANGELOG.md */; };
C80987441EC4882E00EE2C23 /* Todo.swift in Sources */ = {isa = PBXBuildFile; fileRef = C80987431EC4882E00EE2C23 /* Todo.swift */; };
C80987621EC4A28300EE2C23 /* Todo+Plumbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = C809875E1EC49F7400EE2C23 /* Todo+Plumbing.swift */; };
C80987631EC4A28E00EE2C23 /* Todo+Lenses.swift in Sources */ = {isa = PBXBuildFile; fileRef = C809875C1EC49F4900EE2C23 /* Todo+Lenses.swift */; };
Expand Down Expand Up @@ -258,6 +259,7 @@
52D6D9861BEFF229002C0205 /* RxFeedbackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RxFeedbackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
AD2FAA261CD0B6D800659CF4 /* RxFeedback.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = RxFeedback.plist; sourceTree = "<group>"; };
AD2FAA281CD0B6E100659CF4 /* RxFeedbackTests.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = RxFeedbackTests.plist; sourceTree = "<group>"; };
C8047ABB1F41099F0089721B /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
C80987431EC4882E00EE2C23 /* Todo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo.swift; sourceTree = "<group>"; };
C80987581EC4916000EE2C23 /* Todo+Feedback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo+Feedback.swift"; sourceTree = "<group>"; };
C809875C1EC49F4900EE2C23 /* Todo+Lenses.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo+Lenses.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -337,18 +339,15 @@
52D6D9721BEFF229002C0205 = {
isa = PBXGroup;
children = (
C8047ACF1F4109A30089721B /* Packaging */,
C834A8671EB6794F00E6B15E /* RxFeedback */,
C89B963E1EB697D200BDAB24 /* Examples */,
52D6D97D1BEFF229002C0205 /* Products */,
52D6D99C1BEFF38C002C0205 /* Configs */,
C89B96311EB697BF00BDAB24 /* Support */,
C83B7C4F1EB7BA14003055E0 /* Build */,
C8996C661F40A7A0004E5D83 /* Tests */,
C83B7C2B1EB7B794003055E0 /* dependencies.sh */,
C84645941EB794BC0008AD87 /* Package.swift */,
C84645951EB794BC0008AD87 /* RxFeedback.podspec */,
C834A8881EB67A8A00E6B15E /* Rx.xcodeproj */,
C834A86D1EB6796D00E6B15E /* README.md */,
);
sourceTree = "<group>";
};
Expand All @@ -371,6 +370,18 @@
path = Configs;
sourceTree = "<group>";
};
C8047ACF1F4109A30089721B /* Packaging */ = {
isa = PBXGroup;
children = (
C8047ABB1F41099F0089721B /* CHANGELOG.md */,
C83B7C2B1EB7B794003055E0 /* dependencies.sh */,
C84645941EB794BC0008AD87 /* Package.swift */,
C834A86D1EB6796D00E6B15E /* README.md */,
C84645951EB794BC0008AD87 /* RxFeedback.podspec */,
);
name = Packaging;
sourceTree = "<group>";
};
C834A8671EB6794F00E6B15E /* RxFeedback */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -877,6 +888,7 @@
buildActionMask = 2147483647;
files = (
C89B96251EB6964200BDAB24 /* FeedbackLoops.swift in Sources */,
C8047ABC1F41099F0089721B /* CHANGELOG.md in Sources */,
C834A8CB1EB67BAD00E6B15E /* UIView+Extensions.swift in Sources */,
C8996C7A1F40C5B6004E5D83 /* Deprecations.swift in Sources */,
C834A8691EB6795F00E6B15E /* ObservableType+RxFeedback.swift in Sources */,
Expand Down
30 changes: 30 additions & 0 deletions Sources/RxFeedback/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,33 @@ extension ObservableType where E == Any {
}
}

extension UI {
/**
Bi-directional binding of a system State to UI and UI into Events.
*/
@available(*, deprecated, message: "Renamed to version that takes `ObservableSchedulerContext` as argument.", renamed: "bind()")
public static func bind<State, Event>(_ bindings: @escaping (Observable<State>) -> (Bindings<Event>)) -> (Observable<State>) -> Observable<Event> {
return { state in
let scheduler = CurrentThreadScheduler.instance
let context = ObservableSchedulerContext(source: state, scheduler: scheduler)
return bind { bindings($0.source) }(context)
}
}

/**
Bi-directional binding of a system State to UI and UI into Events,
Strongify owner.
*/
@available(*, deprecated, message: "Renamed to version that takes `ObservableSchedulerContext` as argument.", renamed: "bind()")
public static func bind<State, Event, WeakOwner>(_ owner: WeakOwner, _ bindings: @escaping (WeakOwner, Observable<State>) -> (Bindings<Event>))
-> (Observable<State>) -> Observable<Event> where WeakOwner: AnyObject {
weak var weakOwner = owner
return { state in
guard let owner = weakOwner else { return .empty() }
let scheduler = CurrentThreadScheduler.instance
let context = ObservableSchedulerContext(source: state, scheduler: scheduler)

return (self.bind(owner) { bindings($0, $1.source) })(context)
}
}
}
10 changes: 6 additions & 4 deletions Sources/RxFeedback/UIView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ extension UI {
/**
Bi-directional binding of a system State to UI and UI into Events.
*/
public static func bind<State, Event>(_ bindings: @escaping (Observable<State>) -> (Bindings<Event>)) -> (Observable<State>) -> Observable<Event> {
public static func bind<State, Event>(_ bindings: @escaping (ObservableSchedulerContext<State>) -> (Bindings<Event>)) -> (ObservableSchedulerContext<State>) -> Observable<Event> {

return { (state: Observable<State>) -> Observable<Event> in
return { (state: ObservableSchedulerContext<State>) -> Observable<Event> in
return Observable<Event>.using({ () -> Bindings<Event> in
return bindings(state)
}, observableFactory: { (bindings: Bindings<Event>) -> Observable<Event> in
return Observable<Event>.merge(bindings.events)
.observeOn(state.scheduler)
.subscribeOn(state.scheduler)
})
}
}
Expand All @@ -67,8 +69,8 @@ extension UI {
Bi-directional binding of a system State to UI and UI into Events,
Strongify owner.
*/
public static func bind<State, Event, WeakOwner>(_ owner: WeakOwner, _ bindings: @escaping (WeakOwner, Observable<State>) -> (Bindings<Event>))
-> (Observable<State>) -> Observable<Event> where WeakOwner: AnyObject {
public static func bind<State, Event, WeakOwner>(_ owner: WeakOwner, _ bindings: @escaping (WeakOwner, ObservableSchedulerContext<State>) -> (Bindings<Event>))
-> (ObservableSchedulerContext<State>) -> Observable<Event> where WeakOwner: AnyObject {
return bind(bindingsStrongify(owner, bindings))
}

Expand Down

0 comments on commit ac8240d

Please sign in to comment.