From e8457582044c8b43d7622bda8384dfb9fa459790 Mon Sep 17 00:00:00 2001 From: Pavel Lukandiy Date: Mon, 4 Sep 2017 22:20:25 +0300 Subject: [PATCH] DiferredJust for Single --- LeadKit.xcodeproj/project.pbxproj | 12 ++++++ Sources/Classes/Views/XibView.swift | 4 +- .../Single/Single+DeferredJust.swift | 43 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 Sources/Extensions/Single/Single+DeferredJust.swift diff --git a/LeadKit.xcodeproj/project.pbxproj b/LeadKit.xcodeproj/project.pbxproj index a0ca6a65..bfe7f115 100644 --- a/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit.xcodeproj/project.pbxproj @@ -383,6 +383,7 @@ 67E6C2361EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; }; 67E6C2371EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; }; 67E6C2381EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; }; + 82F8BB181F5DDED100C1061B /* Single+DeferredJust.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */; }; BA6C6DB45950382041948FC5 /* Pods_LeadKit_LeadKit_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CFE9323150A9760008093F73 /* Pods_LeadKit_LeadKit_iOS.framework */; }; D6EE55093E404DEA62B03DDF /* Pods_LeadKit_LeadKit_watchOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8590CA7831555C295C5DC572 /* Pods_LeadKit_LeadKit_watchOS.framework */; }; DEE25FE98D40ED1C168F384A /* Pods_LeadKit_LeadKit_iOS_Extensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 887F99C5326BD220C2811BD6 /* Pods_LeadKit_LeadKit_iOS_Extensions.framework */; }; @@ -563,6 +564,7 @@ 67CDEE411EB3AD1C00895905 /* NetworkService+RxLoadImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NetworkService+RxLoadImage.swift"; sourceTree = ""; }; 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleLoadCursor.swift; sourceTree = ""; }; 78405D3B3D3C3E17456877FF /* Pods_LeadKit_iOSTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_iOSTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Single+DeferredJust.swift"; sourceTree = ""; }; 8590CA7831555C295C5DC572 /* Pods_LeadKit_LeadKit_watchOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_LeadKit_watchOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 887F99C5326BD220C2811BD6 /* Pods_LeadKit_LeadKit_iOS_Extensions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_LeadKit_iOS_Extensions.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 95E457F1241D136396FC2420 /* Pods_LeadKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -743,6 +745,7 @@ 671461F01EB3396E00EAB194 /* Observable */, 671461F31EB3396E00EAB194 /* PaginationTableViewWrapperDelegate */, 671461F51EB3396E00EAB194 /* Sequence */, + 82F8BB161F5DDED100C1061B /* Single */, 671461F71EB3396E00EAB194 /* StoryboardProtocol */, 671461FA1EB3396E00EAB194 /* String */, 671461FE1EB3396E00EAB194 /* Support */, @@ -1200,6 +1203,14 @@ name = Products; sourceTree = ""; }; + 82F8BB161F5DDED100C1061B /* Single */ = { + isa = PBXGroup; + children = ( + 82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */, + ); + path = Single; + sourceTree = ""; + }; C90516DF61394D92FF071C0C /* Frameworks */ = { isa = PBXGroup; children = ( @@ -1938,6 +1949,7 @@ 67051ADB1EBC7C36008EADC0 /* SpinnerView.swift in Sources */, 671463581EB3396E00EAB194 /* StoryboardIdentifierProtocol.swift in Sources */, 67A1FF941EBCA65E00D6C89F /* CABasicAnimation+Rotation.swift in Sources */, + 82F8BB181F5DDED100C1061B /* Single+DeferredJust.swift in Sources */, 671463301EB3396E00EAB194 /* CursorType.swift in Sources */, 6714624C1EB3396E00EAB194 /* MapCursor.swift in Sources */, 671463241EB3396E00EAB194 /* Any+TypeName.swift in Sources */, diff --git a/Sources/Classes/Views/XibView.swift b/Sources/Classes/Views/XibView.swift index acdbdb3d..45f27db7 100644 --- a/Sources/Classes/Views/XibView.swift +++ b/Sources/Classes/Views/XibView.swift @@ -60,7 +60,7 @@ open class XibView: UIView { /// Provide initial configuration. Called once open func configure() { - + } - + } diff --git a/Sources/Extensions/Single/Single+DeferredJust.swift b/Sources/Extensions/Single/Single+DeferredJust.swift new file mode 100644 index 00000000..13d9de13 --- /dev/null +++ b/Sources/Extensions/Single/Single+DeferredJust.swift @@ -0,0 +1,43 @@ +// +// Copyright (c) 2017 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import RxSwift + +public extension Single { + + /// Returns an single that invokes the specified factory function whenever a new observer subscribes. + /// + /// - Parameter elementFactory: Element factory function to invoke for each observer + /// that subscribes to the resulting sequence. + /// - Returns: An observable sequence whose observers trigger an invocation of the given element factory function. + static func deferredJust(_ elementFactory: @escaping () throws -> Element) -> Single { + return .create(subscribe: { (observer) -> Disposable in + do { + observer(.success(try elementFactory())) + } catch { + observer(.error(error)) + } + + return Disposables.create() + }) + } +}