Skip to content

Commit 1a5a07a

Browse files
committed
Refactor modules, added operators, updated docs
1 parent 6dc330c commit 1a5a07a

26 files changed

+195
-57
lines changed

Mini-Swift.podspec

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,26 @@ Pod::Spec.new do |s|
6565
ss.tvos.source_files = 'Sources/TestMiddleware/*.swift'
6666
end
6767

68-
s.subspec('Task') do |ss|
68+
s.subspec('MiniTasks') do |ss|
6969
ss.ios.dependency('Mini-Swift/Core')
70-
ss.ios.source_files = 'Sources/Task/*.swift'
70+
ss.ios.source_files = 'Sources/MiniTasks/*.swift'
7171

7272
ss.osx.dependency('Mini-Swift/Core')
73-
ss.osx.source_files = 'Sources/Task/*.swift'
73+
ss.osx.source_files = 'Sources/MiniTasks/*.swift'
7474

7575
ss.tvos.dependency('Mini-Swift/Core')
76-
ss.tvos.source_files = 'Sources/Task/*.swift'
76+
ss.tvos.source_files = 'Sources/MiniTasks/*.swift'
7777
end
7878

79-
s.subspec('Promise') do |ss|
79+
s.subspec('MiniPromises') do |ss|
8080
ss.ios.dependency('Mini-Swift/Core')
81-
ss.ios.source_files = 'Sources/Promise/*.swift'
81+
ss.ios.source_files = 'Sources/MiniPromises/*.swift'
8282

8383
ss.osx.dependency('Mini-Swift/Core')
84-
ss.osx.source_files = 'Sources/Promise/*.swift'
84+
ss.osx.source_files = 'Sources/MiniPromises/*.swift'
8585

8686
ss.tvos.dependency('Mini-Swift/Core')
87-
ss.tvos.source_files = 'Sources/Promise/*.swift'
87+
ss.tvos.source_files = 'Sources/MiniPromises/*.swift'
8888
end
8989

9090
s.preserve_paths = ['Templates/*.stencil']

Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ let package = Package(
2626
),
2727
.library(
2828
name: "MiniTask",
29-
targets: ["Mini", "Task"]
29+
targets: ["Mini", "MiniTasks"]
3030
),
3131
.library(
3232
name: "MiniPromise",
33-
targets: ["Mini", "Promise"]
33+
targets: ["Mini", "MiniPromises"]
3434
),
3535
],
3636
dependencies: [
@@ -65,14 +65,14 @@ let package = Package(
6565
dependencies: ["Mini"]
6666
),
6767
.target(
68-
name: "Task",
68+
name: "MiniTasks",
6969
dependencies: ["Mini"]
7070
),
7171
.target(
72-
name: "Promise",
72+
name: "MiniPromises",
7373
dependencies: ["Mini"]
7474
),
75-
.testTarget(name: "MiniSwiftTests", dependencies: ["Mini", "Task", "Promise", "TestMiddleware", "NIOConcurrencyHelpers", "RxSwift", "Nimble", "RxTest", "RxBlocking"]), // dev
75+
.testTarget(name: "MiniSwiftTests", dependencies: ["Mini", "MiniTasks", "MiniPromises", "TestMiddleware", "NIOConcurrencyHelpers", "RxSwift", "Nimble", "RxTest", "RxBlocking"]), // dev
7676
],
7777
swiftLanguageVersions: [.version("4"), .version("4.2"), .version("5")]
7878
)

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ task(:pods) do
2929
sh('bundle exec pod lib lint --allow-warnings --fail-fast --subspec="Core"')
3030
sh('bundle exec pod lib lint --allow-warnings --fail-fast --subspec="Log"')
3131
sh('bundle exec pod lib lint --allow-warnings --fail-fast --subspec="Test"')
32-
sh('bundle exec pod lib lint --allow-warnings --fail-fast --subspec="Promise"')
33-
sh('bundle exec pod lib lint --allow-warnings --fail-fast --subspec="Task"')
32+
sh('bundle exec pod lib lint --allow-warnings --fail-fast --subspec="MiniPromises"')
33+
sh('bundle exec pod lib lint --allow-warnings --fail-fast --subspec="MiniTasks"')
3434
end
3535

3636
task(:docs) do

Sources/Mini/Mini.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,3 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
17-
#if canImport(MiniTask)
18-
@_exported import MiniTask
19-
#endif
20-
21-
#if canImport(MiniPromise)
22-
@_exported import MiniPromise
23-
#endif

Sources/Mini/Store.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ extension Store {
132132
return objectWillChange.asObservable()
133133
}
134134

135-
public func withStateChanges<T>(in stateComponent: @escaping @autoclosure () -> KeyPath<Element, T>) -> Observable<T> {
136-
map(^stateComponent())
135+
public func withStateChanges<T>(in stateComponent: KeyPath<Element, T>) -> Observable<T> {
136+
map(stateComponent)
137137
}
138138
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright [2019] [BQ]
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import Foundation
18+
19+
public protocol OptionalType {
20+
associatedtype Wrapped
21+
var value: Wrapped? { get }
22+
}
23+
24+
extension Optional: OptionalType {
25+
/// Cast `Optional<Wrapped>` to `Wrapped?`
26+
public var value: Wrapped? {
27+
return self
28+
}
29+
}

Sources/Mini/Utils/RxSwift/ObservableType+Extensions.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,37 @@ extension ObservableType {
4343
public func skippingCurrent() -> Observable<Element> {
4444
skip(1)
4545
}
46+
47+
/**
48+
Selects a property component from an `Element` filtering `nil` and emitting only distinct contiguous elements.
49+
*/
50+
public func select<T: OptionalType>(_ keyPath: KeyPath<Element, T>) -> Observable<T.Wrapped> where T.Wrapped: Equatable {
51+
map(keyPath)
52+
.filterNil()
53+
.distinctUntilChanged()
54+
}
55+
}
56+
57+
public extension ObservableType where Element: OptionalType {
58+
/**
59+
Unwraps and filters out `nil` elements.
60+
- returns: `Observable` of source `Observable`'s elements, with `nil` elements filtered out.
61+
*/
62+
func filterNil() -> Observable<Element.Wrapped> {
63+
return flatMap { element -> Observable<Element.Wrapped> in
64+
guard let value = element.value else {
65+
return Observable<Element.Wrapped>.empty()
66+
}
67+
return Observable<Element.Wrapped>.just(value)
68+
}
69+
}
4670
}
4771

4872
extension ObservableType where Element: StateType {
4973
/**
5074
Maps from a `StateType` property to create an `Observable` that contains the filtered property and all its changes.
5175
*/
52-
public func withStateChanges<T>(in stateComponent: @escaping @autoclosure () -> KeyPath<Element, T>, that componentProperty: @escaping @autoclosure () -> KeyPath<T, Bool>) -> Observable<T> {
53-
return map(stateComponent()).filter(componentProperty())
76+
public func withStateChanges<T>(in stateComponent: KeyPath<Element, T>, that componentProperty: KeyPath<T, Bool>) -> Observable<T> {
77+
return map(stateComponent).filter(componentProperty)
5478
}
5579
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)