├── .gitignore ├── .travis.yml ├── Cartfile ├── Cartfile.resolved ├── Example ├── RxDucksExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── RxDucksExample │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── Modules │ ├── AppReducer.swift │ ├── LoadReducer.swift │ └── UserReduder.swift │ └── ViewController.swift ├── LICENSE ├── README.md ├── RxDucks.podspec ├── RxDucks.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ ├── RxDucks.xcscheme │ └── RxDucksTests.xcscheme ├── RxDucks ├── Action.swift ├── Info.plist ├── Middleware.swift ├── Reducer.swift ├── RxDucks.h ├── State.swift └── Store.swift ├── RxDucksTests ├── Info.plist └── RxDucksTests.swift ├── Support Files └── RxDucks.xcconfig └── codecov.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | os: osx 3 | osx_image: xcode10.2 4 | before_install: 5 | - gem install xcpretty 6 | - carthage update --no-use-binaries --platform ios $@ 7 | before_script: 8 | - set -o pipefail 9 | script: 10 | - xcodebuild test -project ./RxDucks.xcodeproj -scheme RxDucksTests -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=12.2,name=iPhone 8' | xcpretty -c 11 | after_success: 12 | - bash <(curl -s https://codecov.io/bash) 13 | notifications: 14 | email: false 15 | -------------------------------------------------------------------------------- /Cartfile: -------------------------------------------------------------------------------- 1 | github "ReactiveX/RxSwift" ~> 4.4.0 2 | -------------------------------------------------------------------------------- /Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "ReactiveX/RxSwift" "4.4.2" 2 | -------------------------------------------------------------------------------- /Example/RxDucksExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C78AEB9321005806007DA210 /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7F1F29720F7AC3900683D5E /* RxCocoa.framework */; }; 11 | C78AEB9421005806007DA210 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7F1F29620F7AC3900683D5E /* RxSwift.framework */; }; 12 | C7CB4DA02100E69700E78CBF /* LoadReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7CB4D9F2100E69700E78CBF /* LoadReducer.swift */; }; 13 | C7CB4DA22100E71600E78CBF /* AppReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7CB4DA12100E71600E78CBF /* AppReducer.swift */; }; 14 | C7CB4DA42100E75C00E78CBF /* UserReduder.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7CB4DA32100E75C00E78CBF /* UserReduder.swift */; }; 15 | C7F1F28320F7A9DB00683D5E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F28220F7A9DB00683D5E /* AppDelegate.swift */; }; 16 | C7F1F28520F7A9DB00683D5E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F28420F7A9DB00683D5E /* ViewController.swift */; }; 17 | C7F1F28820F7A9DB00683D5E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7F1F28620F7A9DB00683D5E /* Main.storyboard */; }; 18 | C7F1F28A20F7A9DE00683D5E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7F1F28920F7A9DE00683D5E /* Assets.xcassets */; }; 19 | C7F1F28D20F7A9DE00683D5E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C7F1F28B20F7A9DE00683D5E /* LaunchScreen.storyboard */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | C7F1F2A320F7ACC900683D5E /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = C7F1F29E20F7ACC900683D5E /* RxDucks.xcodeproj */; 26 | proxyType = 2; 27 | remoteGlobalIDString = C7F1F25620F7972800683D5E; 28 | remoteInfo = RxDucks; 29 | }; 30 | C7F1F2A520F7ACC900683D5E /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = C7F1F29E20F7ACC900683D5E /* RxDucks.xcodeproj */; 33 | proxyType = 2; 34 | remoteGlobalIDString = C7F1F25F20F7972800683D5E; 35 | remoteInfo = RxDucksTests; 36 | }; 37 | C7F1F2BE20F7B52600683D5E /* PBXContainerItemProxy */ = { 38 | isa = PBXContainerItemProxy; 39 | containerPortal = C7F1F29E20F7ACC900683D5E /* RxDucks.xcodeproj */; 40 | proxyType = 1; 41 | remoteGlobalIDString = C7F1F25520F7972800683D5E; 42 | remoteInfo = RxDucks; 43 | }; 44 | /* End PBXContainerItemProxy section */ 45 | 46 | /* Begin PBXFileReference section */ 47 | C7CB4D9F2100E69700E78CBF /* LoadReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadReducer.swift; sourceTree = ""; }; 48 | C7CB4DA12100E71600E78CBF /* AppReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppReducer.swift; sourceTree = ""; }; 49 | C7CB4DA32100E75C00E78CBF /* UserReduder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserReduder.swift; sourceTree = ""; }; 50 | C7F1F27F20F7A9DB00683D5E /* RxDucksExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RxDucksExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | C7F1F28220F7A9DB00683D5E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 52 | C7F1F28420F7A9DB00683D5E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 53 | C7F1F28720F7A9DB00683D5E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 54 | C7F1F28920F7A9DE00683D5E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 55 | C7F1F28C20F7A9DE00683D5E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 56 | C7F1F28E20F7A9DE00683D5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | C7F1F29620F7AC3900683D5E /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = ../Carthage/Build/iOS/RxSwift.framework; sourceTree = ""; }; 58 | C7F1F29720F7AC3900683D5E /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = ../Carthage/Build/iOS/RxCocoa.framework; sourceTree = ""; }; 59 | C7F1F29A20F7AC8C00683D5E /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = ""; }; 60 | C7F1F29B20F7AC8C00683D5E /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = Carthage/Build/iOS/RxCocoa.framework; sourceTree = ""; }; 61 | C7F1F29E20F7ACC900683D5E /* RxDucks.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RxDucks.xcodeproj; path = ../RxDucks.xcodeproj; sourceTree = ""; }; 62 | /* End PBXFileReference section */ 63 | 64 | /* Begin PBXFrameworksBuildPhase section */ 65 | C7F1F27C20F7A9DB00683D5E /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | C78AEB9321005806007DA210 /* RxCocoa.framework in Frameworks */, 70 | C78AEB9421005806007DA210 /* RxSwift.framework in Frameworks */, 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | C7CB4D982100E5EA00E78CBF /* Modules */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | C7CB4DA12100E71600E78CBF /* AppReducer.swift */, 81 | C7CB4D9F2100E69700E78CBF /* LoadReducer.swift */, 82 | C7CB4DA32100E75C00E78CBF /* UserReduder.swift */, 83 | ); 84 | path = Modules; 85 | sourceTree = ""; 86 | }; 87 | C7F1F27620F7A9DB00683D5E = { 88 | isa = PBXGroup; 89 | children = ( 90 | C7F1F29E20F7ACC900683D5E /* RxDucks.xcodeproj */, 91 | C7F1F28120F7A9DB00683D5E /* RxDucksExample */, 92 | C7F1F28020F7A9DB00683D5E /* Products */, 93 | C7F1F29520F7AC3900683D5E /* Frameworks */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | C7F1F28020F7A9DB00683D5E /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | C7F1F27F20F7A9DB00683D5E /* RxDucksExample.app */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | C7F1F28120F7A9DB00683D5E /* RxDucksExample */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | C7CB4D982100E5EA00E78CBF /* Modules */, 109 | C7F1F28220F7A9DB00683D5E /* AppDelegate.swift */, 110 | C7F1F28420F7A9DB00683D5E /* ViewController.swift */, 111 | C7F1F28620F7A9DB00683D5E /* Main.storyboard */, 112 | C7F1F28920F7A9DE00683D5E /* Assets.xcassets */, 113 | C7F1F28B20F7A9DE00683D5E /* LaunchScreen.storyboard */, 114 | C7F1F28E20F7A9DE00683D5E /* Info.plist */, 115 | ); 116 | path = RxDucksExample; 117 | sourceTree = ""; 118 | }; 119 | C7F1F29520F7AC3900683D5E /* Frameworks */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | C7F1F29B20F7AC8C00683D5E /* RxCocoa.framework */, 123 | C7F1F29A20F7AC8C00683D5E /* RxSwift.framework */, 124 | C7F1F29720F7AC3900683D5E /* RxCocoa.framework */, 125 | C7F1F29620F7AC3900683D5E /* RxSwift.framework */, 126 | ); 127 | name = Frameworks; 128 | sourceTree = ""; 129 | }; 130 | C7F1F29F20F7ACC900683D5E /* Products */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | C7F1F2A420F7ACC900683D5E /* RxDucks.framework */, 134 | C7F1F2A620F7ACC900683D5E /* RxDucksTests.xctest */, 135 | ); 136 | name = Products; 137 | sourceTree = ""; 138 | }; 139 | /* End PBXGroup section */ 140 | 141 | /* Begin PBXNativeTarget section */ 142 | C7F1F27E20F7A9DB00683D5E /* RxDucksExample */ = { 143 | isa = PBXNativeTarget; 144 | buildConfigurationList = C7F1F29120F7A9DE00683D5E /* Build configuration list for PBXNativeTarget "RxDucksExample" */; 145 | buildPhases = ( 146 | C7F1F27B20F7A9DB00683D5E /* Sources */, 147 | C7F1F27C20F7A9DB00683D5E /* Frameworks */, 148 | C7F1F27D20F7A9DB00683D5E /* Resources */, 149 | C7F1F29420F7ABE100683D5E /* Carthage */, 150 | ); 151 | buildRules = ( 152 | ); 153 | dependencies = ( 154 | C7F1F2BF20F7B52600683D5E /* PBXTargetDependency */, 155 | ); 156 | name = RxDucksExample; 157 | productName = RxDucksExample; 158 | productReference = C7F1F27F20F7A9DB00683D5E /* RxDucksExample.app */; 159 | productType = "com.apple.product-type.application"; 160 | }; 161 | /* End PBXNativeTarget section */ 162 | 163 | /* Begin PBXProject section */ 164 | C7F1F27720F7A9DB00683D5E /* Project object */ = { 165 | isa = PBXProject; 166 | attributes = { 167 | LastSwiftUpdateCheck = 0930; 168 | LastUpgradeCheck = 0930; 169 | ORGANIZATIONNAME = "CyberAgent, Inc."; 170 | TargetAttributes = { 171 | C7F1F27E20F7A9DB00683D5E = { 172 | CreatedOnToolsVersion = 9.3.1; 173 | }; 174 | }; 175 | }; 176 | buildConfigurationList = C7F1F27A20F7A9DB00683D5E /* Build configuration list for PBXProject "RxDucksExample" */; 177 | compatibilityVersion = "Xcode 9.3"; 178 | developmentRegion = en; 179 | hasScannedForEncodings = 0; 180 | knownRegions = ( 181 | en, 182 | Base, 183 | ); 184 | mainGroup = C7F1F27620F7A9DB00683D5E; 185 | productRefGroup = C7F1F28020F7A9DB00683D5E /* Products */; 186 | projectDirPath = ""; 187 | projectReferences = ( 188 | { 189 | ProductGroup = C7F1F29F20F7ACC900683D5E /* Products */; 190 | ProjectRef = C7F1F29E20F7ACC900683D5E /* RxDucks.xcodeproj */; 191 | }, 192 | ); 193 | projectRoot = ""; 194 | targets = ( 195 | C7F1F27E20F7A9DB00683D5E /* RxDucksExample */, 196 | ); 197 | }; 198 | /* End PBXProject section */ 199 | 200 | /* Begin PBXReferenceProxy section */ 201 | C7F1F2A420F7ACC900683D5E /* RxDucks.framework */ = { 202 | isa = PBXReferenceProxy; 203 | fileType = wrapper.framework; 204 | path = RxDucks.framework; 205 | remoteRef = C7F1F2A320F7ACC900683D5E /* PBXContainerItemProxy */; 206 | sourceTree = BUILT_PRODUCTS_DIR; 207 | }; 208 | C7F1F2A620F7ACC900683D5E /* RxDucksTests.xctest */ = { 209 | isa = PBXReferenceProxy; 210 | fileType = wrapper.cfbundle; 211 | path = RxDucksTests.xctest; 212 | remoteRef = C7F1F2A520F7ACC900683D5E /* PBXContainerItemProxy */; 213 | sourceTree = BUILT_PRODUCTS_DIR; 214 | }; 215 | /* End PBXReferenceProxy section */ 216 | 217 | /* Begin PBXResourcesBuildPhase section */ 218 | C7F1F27D20F7A9DB00683D5E /* Resources */ = { 219 | isa = PBXResourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | C7F1F28D20F7A9DE00683D5E /* LaunchScreen.storyboard in Resources */, 223 | C7F1F28A20F7A9DE00683D5E /* Assets.xcassets in Resources */, 224 | C7F1F28820F7A9DB00683D5E /* Main.storyboard in Resources */, 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | }; 228 | /* End PBXResourcesBuildPhase section */ 229 | 230 | /* Begin PBXShellScriptBuildPhase section */ 231 | C7F1F29420F7ABE100683D5E /* Carthage */ = { 232 | isa = PBXShellScriptBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | ); 236 | inputPaths = ( 237 | "$(SRCROOT)/../Carthage/Build/iOS/RxCocoa.framework", 238 | "$(SRCROOT)/../Carthage/Build/iOS/RxSwift.framework", 239 | ); 240 | name = Carthage; 241 | outputPaths = ( 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | shellPath = /bin/sh; 245 | shellScript = "carthage copy-frameworks"; 246 | }; 247 | /* End PBXShellScriptBuildPhase section */ 248 | 249 | /* Begin PBXSourcesBuildPhase section */ 250 | C7F1F27B20F7A9DB00683D5E /* Sources */ = { 251 | isa = PBXSourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | C7F1F28520F7A9DB00683D5E /* ViewController.swift in Sources */, 255 | C7CB4DA02100E69700E78CBF /* LoadReducer.swift in Sources */, 256 | C7CB4DA42100E75C00E78CBF /* UserReduder.swift in Sources */, 257 | C7CB4DA22100E71600E78CBF /* AppReducer.swift in Sources */, 258 | C7F1F28320F7A9DB00683D5E /* AppDelegate.swift in Sources */, 259 | ); 260 | runOnlyForDeploymentPostprocessing = 0; 261 | }; 262 | /* End PBXSourcesBuildPhase section */ 263 | 264 | /* Begin PBXTargetDependency section */ 265 | C7F1F2BF20F7B52600683D5E /* PBXTargetDependency */ = { 266 | isa = PBXTargetDependency; 267 | name = RxDucks; 268 | targetProxy = C7F1F2BE20F7B52600683D5E /* PBXContainerItemProxy */; 269 | }; 270 | /* End PBXTargetDependency section */ 271 | 272 | /* Begin PBXVariantGroup section */ 273 | C7F1F28620F7A9DB00683D5E /* Main.storyboard */ = { 274 | isa = PBXVariantGroup; 275 | children = ( 276 | C7F1F28720F7A9DB00683D5E /* Base */, 277 | ); 278 | name = Main.storyboard; 279 | sourceTree = ""; 280 | }; 281 | C7F1F28B20F7A9DE00683D5E /* LaunchScreen.storyboard */ = { 282 | isa = PBXVariantGroup; 283 | children = ( 284 | C7F1F28C20F7A9DE00683D5E /* Base */, 285 | ); 286 | name = LaunchScreen.storyboard; 287 | sourceTree = ""; 288 | }; 289 | /* End PBXVariantGroup section */ 290 | 291 | /* Begin XCBuildConfiguration section */ 292 | C7F1F28F20F7A9DE00683D5E /* Debug */ = { 293 | isa = XCBuildConfiguration; 294 | buildSettings = { 295 | ALWAYS_SEARCH_USER_PATHS = NO; 296 | CLANG_ANALYZER_NONNULL = YES; 297 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 298 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 299 | CLANG_CXX_LIBRARY = "libc++"; 300 | CLANG_ENABLE_MODULES = YES; 301 | CLANG_ENABLE_OBJC_ARC = YES; 302 | CLANG_ENABLE_OBJC_WEAK = YES; 303 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 304 | CLANG_WARN_BOOL_CONVERSION = YES; 305 | CLANG_WARN_COMMA = YES; 306 | CLANG_WARN_CONSTANT_CONVERSION = YES; 307 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 308 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 309 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 310 | CLANG_WARN_EMPTY_BODY = YES; 311 | CLANG_WARN_ENUM_CONVERSION = YES; 312 | CLANG_WARN_INFINITE_RECURSION = YES; 313 | CLANG_WARN_INT_CONVERSION = YES; 314 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 315 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 316 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 317 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 318 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 319 | CLANG_WARN_STRICT_PROTOTYPES = YES; 320 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 321 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 322 | CLANG_WARN_UNREACHABLE_CODE = YES; 323 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 324 | CODE_SIGN_IDENTITY = "iPhone Developer"; 325 | COPY_PHASE_STRIP = NO; 326 | DEBUG_INFORMATION_FORMAT = dwarf; 327 | ENABLE_STRICT_OBJC_MSGSEND = YES; 328 | ENABLE_TESTABILITY = YES; 329 | GCC_C_LANGUAGE_STANDARD = gnu11; 330 | GCC_DYNAMIC_NO_PIC = NO; 331 | GCC_NO_COMMON_BLOCKS = YES; 332 | GCC_OPTIMIZATION_LEVEL = 0; 333 | GCC_PREPROCESSOR_DEFINITIONS = ( 334 | "DEBUG=1", 335 | "$(inherited)", 336 | ); 337 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 338 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 339 | GCC_WARN_UNDECLARED_SELECTOR = YES; 340 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 341 | GCC_WARN_UNUSED_FUNCTION = YES; 342 | GCC_WARN_UNUSED_VARIABLE = YES; 343 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 344 | MTL_ENABLE_DEBUG_INFO = YES; 345 | ONLY_ACTIVE_ARCH = YES; 346 | SDKROOT = iphoneos; 347 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 348 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 349 | }; 350 | name = Debug; 351 | }; 352 | C7F1F29020F7A9DE00683D5E /* Release */ = { 353 | isa = XCBuildConfiguration; 354 | buildSettings = { 355 | ALWAYS_SEARCH_USER_PATHS = NO; 356 | CLANG_ANALYZER_NONNULL = YES; 357 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 358 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 359 | CLANG_CXX_LIBRARY = "libc++"; 360 | CLANG_ENABLE_MODULES = YES; 361 | CLANG_ENABLE_OBJC_ARC = YES; 362 | CLANG_ENABLE_OBJC_WEAK = YES; 363 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 364 | CLANG_WARN_BOOL_CONVERSION = YES; 365 | CLANG_WARN_COMMA = YES; 366 | CLANG_WARN_CONSTANT_CONVERSION = YES; 367 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 368 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 369 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 370 | CLANG_WARN_EMPTY_BODY = YES; 371 | CLANG_WARN_ENUM_CONVERSION = YES; 372 | CLANG_WARN_INFINITE_RECURSION = YES; 373 | CLANG_WARN_INT_CONVERSION = YES; 374 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 375 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 376 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 377 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 378 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 379 | CLANG_WARN_STRICT_PROTOTYPES = YES; 380 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 381 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 382 | CLANG_WARN_UNREACHABLE_CODE = YES; 383 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 384 | CODE_SIGN_IDENTITY = "iPhone Developer"; 385 | COPY_PHASE_STRIP = NO; 386 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 387 | ENABLE_NS_ASSERTIONS = NO; 388 | ENABLE_STRICT_OBJC_MSGSEND = YES; 389 | GCC_C_LANGUAGE_STANDARD = gnu11; 390 | GCC_NO_COMMON_BLOCKS = YES; 391 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 392 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 393 | GCC_WARN_UNDECLARED_SELECTOR = YES; 394 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 395 | GCC_WARN_UNUSED_FUNCTION = YES; 396 | GCC_WARN_UNUSED_VARIABLE = YES; 397 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 398 | MTL_ENABLE_DEBUG_INFO = NO; 399 | SDKROOT = iphoneos; 400 | SWIFT_COMPILATION_MODE = wholemodule; 401 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 402 | VALIDATE_PRODUCT = YES; 403 | }; 404 | name = Release; 405 | }; 406 | C7F1F29220F7A9DE00683D5E /* Debug */ = { 407 | isa = XCBuildConfiguration; 408 | buildSettings = { 409 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 410 | CODE_SIGN_STYLE = Automatic; 411 | FRAMEWORK_SEARCH_PATHS = ( 412 | "$(inherited)", 413 | "$(PROJECT_DIR)/../Carthage/Build/iOS", 414 | ); 415 | INFOPLIST_FILE = RxDucksExample/Info.plist; 416 | LD_RUNPATH_SEARCH_PATHS = ( 417 | "$(inherited)", 418 | "@executable_path/Frameworks", 419 | ); 420 | PRODUCT_BUNDLE_IDENTIFIER = jp.co.cyberagent.RxDucksExample; 421 | PRODUCT_NAME = "$(TARGET_NAME)"; 422 | SWIFT_VERSION = 4.0; 423 | TARGETED_DEVICE_FAMILY = "1,2"; 424 | }; 425 | name = Debug; 426 | }; 427 | C7F1F29320F7A9DE00683D5E /* Release */ = { 428 | isa = XCBuildConfiguration; 429 | buildSettings = { 430 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 431 | CODE_SIGN_STYLE = Automatic; 432 | FRAMEWORK_SEARCH_PATHS = ( 433 | "$(inherited)", 434 | "$(PROJECT_DIR)/../Carthage/Build/iOS", 435 | ); 436 | INFOPLIST_FILE = RxDucksExample/Info.plist; 437 | LD_RUNPATH_SEARCH_PATHS = ( 438 | "$(inherited)", 439 | "@executable_path/Frameworks", 440 | ); 441 | PRODUCT_BUNDLE_IDENTIFIER = jp.co.cyberagent.RxDucksExample; 442 | PRODUCT_NAME = "$(TARGET_NAME)"; 443 | SWIFT_VERSION = 4.0; 444 | TARGETED_DEVICE_FAMILY = "1,2"; 445 | }; 446 | name = Release; 447 | }; 448 | /* End XCBuildConfiguration section */ 449 | 450 | /* Begin XCConfigurationList section */ 451 | C7F1F27A20F7A9DB00683D5E /* Build configuration list for PBXProject "RxDucksExample" */ = { 452 | isa = XCConfigurationList; 453 | buildConfigurations = ( 454 | C7F1F28F20F7A9DE00683D5E /* Debug */, 455 | C7F1F29020F7A9DE00683D5E /* Release */, 456 | ); 457 | defaultConfigurationIsVisible = 0; 458 | defaultConfigurationName = Release; 459 | }; 460 | C7F1F29120F7A9DE00683D5E /* Build configuration list for PBXNativeTarget "RxDucksExample" */ = { 461 | isa = XCConfigurationList; 462 | buildConfigurations = ( 463 | C7F1F29220F7A9DE00683D5E /* Debug */, 464 | C7F1F29320F7A9DE00683D5E /* Release */, 465 | ); 466 | defaultConfigurationIsVisible = 0; 467 | defaultConfigurationName = Release; 468 | }; 469 | /* End XCConfigurationList section */ 470 | }; 471 | rootObject = C7F1F27720F7A9DB00683D5E /* Project object */; 472 | } 473 | -------------------------------------------------------------------------------- /Example/RxDucksExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/RxDucksExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/RxDucksExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // RxDucksExample 4 | // 5 | // Created by Kyohei Ito on 2018/07/13. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/RxDucksExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Example/RxDucksExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/RxDucksExample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/RxDucksExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 29 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Example/RxDucksExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/RxDucksExample/Modules/AppReducer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppReducer.swift 3 | // RxDucksExample 4 | // 5 | // Created by Kyohei Ito on 2018/07/20. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import RxDucks 10 | 11 | struct AppState: State { 12 | var user = UserState() 13 | var load = LoadState() 14 | } 15 | 16 | struct AppReducer: Reducer { 17 | func reduce(_ state: AppState, action: Action) -> AppState { 18 | return AppState(user: UserReduder.reduce(state.user, action: action), 19 | load: LoadReducer.reduce(state.load, action: action)) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example/RxDucksExample/Modules/LoadReducer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LoadReducer.swift 3 | // RxDucksExample 4 | // 5 | // Created by Kyohei Ito on 2018/07/20. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import RxSwift 10 | import RxCocoa 11 | import RxDucks 12 | 13 | enum LoadAction: Action { 14 | case loading, progress(Int), loaded, cancel 15 | } 16 | 17 | extension ActionCreator { 18 | static func loading() -> LoadAction { 19 | return .loading 20 | } 21 | static func progress(_ progress: Int) -> LoadAction { 22 | return .progress(progress) 23 | } 24 | static func loaded() -> LoadAction { 25 | return .loaded 26 | } 27 | static func cancel() -> LoadAction { 28 | return .cancel 29 | } 30 | } 31 | 32 | struct LoadState: State { 33 | var progress = 0 34 | var loading = false 35 | var canceled = false 36 | } 37 | 38 | struct LoadReducer { 39 | static func reduce(_ state: LoadState, action: Action) -> LoadState { 40 | switch action { 41 | case is LogOutAction: 42 | return LoadState(progress: 0, loading: state.loading, canceled: false) 43 | default: 44 | break 45 | } 46 | 47 | switch action as? LoadAction { 48 | case .loading?: 49 | return LoadState(progress: 0, loading: true, canceled: false) 50 | case .progress(let progress)?: 51 | return LoadState(progress: progress, loading: state.loading, canceled: false) 52 | case .loaded?: 53 | return LoadState(progress: state.progress, loading: false, canceled: false) 54 | case .cancel?: 55 | return LoadState(progress: 0, loading: false, canceled: true) 56 | default: 57 | break 58 | } 59 | 60 | return state 61 | } 62 | } 63 | 64 | struct LoadMiddleware: Middleware { 65 | private let cancel = PublishRelay() 66 | 67 | func on(_ store: Store, action: Action, next: @escaping (Action) -> Void) -> Disposable { 68 | switch action { 69 | case is LogInAction: 70 | store.dispatch(ActionCreator.loading()) 71 | 72 | return Observable.interval(0.01, scheduler: ConcurrentDispatchQueueScheduler(qos: .default)) 73 | .takeUntil(cancel) 74 | .subscribe(onNext: { progress in 75 | store.dispatch(ActionCreator.progress(progress)) 76 | 77 | if progress >= 100 { 78 | next(ActionCreator.loaded()) 79 | } 80 | }) 81 | default: 82 | switch action as? LoadAction { 83 | case .cancel?: 84 | cancel.accept(()) 85 | default: 86 | break 87 | } 88 | next(action) 89 | } 90 | 91 | return Disposables.create() 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Example/RxDucksExample/Modules/UserReduder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UserReduder.swift 3 | // RxDucksExample 4 | // 5 | // Created by Kyohei Ito on 2018/07/20. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import RxDucks 10 | 11 | struct LogInAction: Action {} 12 | struct LogOutAction: Action {} 13 | 14 | extension ActionCreator { 15 | static func logIn() -> LogInAction { 16 | return LogInAction() 17 | } 18 | 19 | static func logOut() -> LogOutAction { 20 | return LogOutAction() 21 | } 22 | } 23 | 24 | struct UserState: State { 25 | var loggedIn = false 26 | } 27 | 28 | struct UserReduder { 29 | static func reduce(_ state: UserState, action: Action) -> UserState { 30 | switch action { 31 | case is LogOutAction: 32 | return UserState(loggedIn: false) 33 | default: 34 | break 35 | } 36 | 37 | switch action as? LoadAction { 38 | case .loaded?: 39 | return UserState(loggedIn: true) 40 | default: 41 | break 42 | } 43 | 44 | return state 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Example/RxDucksExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // RxDucksExample 4 | // 5 | // Created by Kyohei Ito on 2018/07/13. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import RxSwift 11 | import RxDucks 12 | 13 | class ViewController: UIViewController { 14 | let disposeBag = DisposeBag() 15 | let store = Store(reducer: AppReducer(), state: AppState(), middlewares: LoadMiddleware()) 16 | 17 | @IBOutlet weak var statusLabel: UILabel! 18 | @IBOutlet weak var logInButton: UIButton! 19 | @IBOutlet weak var logOutButton: UIButton! 20 | @IBOutlet weak var cancelButton: UIButton! { 21 | didSet { 22 | cancelButton.layer.cornerRadius = cancelButton.bounds.height / 2 23 | } 24 | } 25 | @IBOutlet weak var progress: UIProgressView! 26 | @IBOutlet weak var indicator: UIActivityIndicatorView! { 27 | didSet { 28 | indicator.startAnimating() 29 | } 30 | } 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | store.specifyState { !$0.load.loading } 36 | .bind(to: cancelButton.rx.isHidden) 37 | .disposed(by: disposeBag) 38 | 39 | store.specifyState { !$0.load.loading } 40 | .bind(to: indicator.rx.isHidden) 41 | .disposed(by: disposeBag) 42 | 43 | store.specifyState { !$0.load.loading } 44 | .bind(to: logInButton.rx.isEnabled) 45 | .disposed(by: disposeBag) 46 | 47 | store.specifyState { $0.load.loading } 48 | .filter { $0 } 49 | .map { _ in "Loading" } 50 | .bind(to: statusLabel.rx.text) 51 | .disposed(by: disposeBag) 52 | 53 | store.specifyState { Float($0.load.progress) / 100 } 54 | .bind(to: progress.rx.progress) 55 | .disposed(by: disposeBag) 56 | 57 | store.specifyNewState { $0.user.loggedIn } 58 | .map { $0 ? "Log In" : "Log Out" } 59 | .bind(to: statusLabel.rx.text) 60 | .disposed(by: disposeBag) 61 | 62 | store.specifyNewState { $0.load.canceled } 63 | .filter { $0 } 64 | .map { _ in "Canceled" } 65 | .bind(to: statusLabel.rx.text) 66 | .disposed(by: disposeBag) 67 | 68 | let loggedIn = logInButton.rx.tap 69 | .withLatestFrom(store.specifyState { $0.user.loggedIn }) 70 | .share() 71 | 72 | loggedIn 73 | .filter { $0 } 74 | .map { _ in "Already Logged In" } 75 | .bind(to: statusLabel.rx.text) 76 | .disposed(by: disposeBag) 77 | 78 | loggedIn 79 | .filter { !$0 } 80 | .map { _ in ActionCreator.logIn() } 81 | .bind(to: store.dispatcher) 82 | .disposed(by: disposeBag) 83 | 84 | let loggedOut = logOutButton.rx.tap 85 | .withLatestFrom(store.specifyState { !$0.user.loggedIn }) 86 | .share() 87 | 88 | loggedOut 89 | .filter { $0 } 90 | .map { _ in "Already Logged Out" } 91 | .bind(to: statusLabel.rx.text) 92 | .disposed(by: disposeBag) 93 | 94 | loggedOut 95 | .filter { !$0 } 96 | .map { _ in ActionCreator.logOut() } 97 | .bind(to: store.dispatcher) 98 | .disposed(by: disposeBag) 99 | 100 | cancelButton.rx.tap 101 | .map { ActionCreator.cancel() } 102 | .bind(to: store.dispatcher) 103 | .disposed(by: disposeBag) 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 CyberAgent, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :duck: RxDucks 2 | 3 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 4 | [![Build Status](https://travis-ci.org/cats-oss/RxDucks.svg?branch=master)](https://travis-ci.org/cats-oss/RxDucks) 5 | [![codecov](https://codecov.io/gh/cats-oss/RxDucks/branch/master/graph/badge.svg)](https://codecov.io/gh/cats-oss/RxDucks) 6 | [![Version](https://img.shields.io/cocoapods/v/RxDucks.svg?style=flat)](http://cocoadocs.org/docsets/RxDucks) 7 | [![License](https://img.shields.io/cocoapods/l/RxDucks.svg?style=flat)](http://cocoadocs.org/docsets/RxDucks) 8 | [![Platform](https://img.shields.io/cocoapods/p/RxDucks.svg?style=flat)](http://cocoadocs.org/docsets/RxDucks) 9 | 10 | ## What's RxDucks? 11 | 12 | RxDucks is a Redux-like framework working on RxSwift. There are various Redux frameworks, this is a framework specialized for RxSwift. 13 | 14 | Redux is one of the modern application architectures. For details, refer to the following links. 15 | 16 | - [Redux](https://redux.js.org/) 17 | - [About ReactiveReSwift](https://reswift.github.io/ReactiveReSwift/master/about-reactivereswift.html) 18 | 19 | 20 | ## Requirements 21 | 22 | - Swift 5.0 23 | - RxSwift 4.4 or later 24 | 25 | ## How to Install 26 | 27 | #### CocoaPods 28 | 29 | Add the following to your `Podfile`: 30 | 31 | ```Ruby 32 | pod "RxDucks" 33 | ``` 34 | 35 | #### Carthage 36 | 37 | Add the following to your `Cartfile`: 38 | 39 | ```Ruby 40 | github "cats-oss/RxDucks" 41 | ``` 42 | 43 | ## How to use RxDucks 44 | 45 | The minimum required is `State`, `Action`, `Reducer` and `Store`. 46 | 47 | ### State 48 | 49 | For `State`, prepare property that application state want. For example, when it want the counter that users can increase or decrease, should create counting property. 50 | 51 | It does not have to make immutable necessarily. 52 | 53 | ```swift 54 | struct AppState: State { 55 | var counter: Int = 0 56 | var user = UserState() 57 | } 58 | 59 | struct UserState: State { 60 | var loggedIn = false 61 | } 62 | ``` 63 | 64 | ### Action 65 | 66 | Prepare actions for increase and decrease. 67 | 68 | ```swift 69 | struct IncreaseAction: Action {} 70 | struct DecreaseAction: Action {} 71 | struct LogInAction: Action {} 72 | ``` 73 | 74 | It does not matter whether it is a struct or not, as long as it complies with the `Action` protocol. 75 | 76 | ```swift 77 | enum CounterAction: Action { 78 | case increase, decrease 79 | } 80 | ``` 81 | 82 | If it does not want to notify state to store, use `IgnorableAction`. 83 | 84 | ```swift 85 | struct ResetAction: IgnorableAction {} 86 | ``` 87 | 88 | ### Reducer 89 | 90 | Have to prepare Reducer that complies with the Reducer protocol. 91 | 92 | ```swift 93 | struct AppReducer: Reducer { 94 | func reduce(_ state: AppState, action: Action) -> AppState { 95 | var state = state 96 | 97 | switch action { 98 | case is IncreaseAction: 99 | state.counter += 1 100 | case is DecreaseAction: 101 | state.counter -= 1 102 | case is ResetAction: 103 | state.counter = 0 104 | case is LogInAction: 105 | state.user.loggedIn = true 106 | default: 107 | break 108 | } 109 | 110 | return state 111 | } 112 | } 113 | ``` 114 | 115 | It possible that calls the reducer in main reducer. In that case, it is not necessary to conform to the `Reducer` protocol. 116 | 117 | ```swift 118 | struct CounterReduder { 119 | static func reduce(_ state: Int, action: Action) -> Int { 120 | switch action { 121 | case is IncreaseAction: 122 | return state + 1 123 | case is DecreaseAction: 124 | return state - 1 125 | case is ResetAction: 126 | return 0 127 | default: 128 | return state 129 | } 130 | } 131 | } 132 | 133 | struct UserReduder { 134 | static func reduce(_ state: UserState, action: Action) -> UserState { 135 | switch action { 136 | case is LogInAction: 137 | return UserState(loggedIn: true) 138 | default: 139 | return state 140 | } 141 | } 142 | } 143 | 144 | struct AppReducer: Reducer { 145 | func reduce(_ state: AppState, action: Action) -> AppState { 146 | return AppState(counter: CounterReduder.reduce(state.counter, action: action), 147 | user: UserReduder.reduce(state.user, action: action)) 148 | } 149 | } 150 | ``` 151 | 152 | ### Store 153 | 154 | Initialize with the initial state and the instance of the main `Reducer`. 155 | 156 | ```swift 157 | let store = Store(reducer: AppReducer(), state: AppState()) 158 | ``` 159 | 160 | It can also make the shared instance. 161 | 162 | ```swift 163 | extension Store where State == AppState { 164 | static let shared = Store(reducer: AppReducer(), state: AppState()) 165 | } 166 | ``` 167 | 168 | #### Subscribe to the state 169 | 170 | It can subscribe to change the state. `state` subscribes all change. `specifyState` subscribes specific state change. Then, when the `Store` subscribes to `state` and `specifyState`, it observes the current state, but when subscribes to `newState` and `specifyNewState`, it does not observe the current state. 171 | 172 | ```swift 173 | class ViewController: UIViewController { 174 | let disposeBag = DisposeBag() 175 | let store = Store(reducer: AppReducer(), state: AppState()) 176 | 177 | @IBOutlet weak var statusLabel: UILabel! 178 | @IBOutlet weak var counterLabel: UILabel! 179 | 180 | override func viewDidLoad() { 181 | super.viewDidLoad() 182 | 183 | store.state 184 | .subscribe(onNext: { 185 | print($0) 186 | }) 187 | .disposed(by: disposeBag) 188 | 189 | store.specifyNewState { $0.user.loggedIn } 190 | .map { $0 ? "Log In" : "Log Out" } 191 | .bind(to: statusLabel.rx.text) 192 | .disposed(by: disposeBag) 193 | 194 | store.specifyState { $0.counter } 195 | .map { "\($0)" } 196 | .bind(to: counterLabel.rx.text) 197 | .disposed(by: disposeBag) 198 | } 199 | } 200 | ``` 201 | 202 | #### Dispatch an action 203 | 204 | It can dispatch an action to mutate the state. 205 | 206 | ```swift 207 | store.dispatch(IncreaseAction()) 208 | ``` 209 | 210 | Also, it possible to bind using `dispatcher`. 211 | 212 | ```swift 213 | class ViewController: UIViewController { 214 | let disposeBag = DisposeBag() 215 | let store = Store(reducer: AppReducer(), state: AppState()) 216 | 217 | @IBOutlet weak var increaseButton: UIButton! 218 | 219 | override func viewDidLoad() { 220 | super.viewDidLoad() 221 | 222 | increaseButton.rx.tap 223 | .map { IncreaseAction() } 224 | .bind(to: store.dispatcher) 225 | .disposed(by: disposeBag) 226 | } 227 | } 228 | ``` 229 | 230 | ### Middleware 231 | 232 | It is similar to Reducer, but it can not mutate the state. What `Middleware` can do is to dispatch and change new Actions. 233 | 234 | ```swift 235 | struct LoggingMiddleware: Middleware { 236 | func on(_ store: Store, action: Action, next: @escaping (Action) -> Void) -> Disposable { 237 | print(action) 238 | next(action) 239 | return Disposables.create() 240 | } 241 | } 242 | ``` 243 | 244 | The reason for returning `Disposable` is to facilitate asynchronous processing. It has to execute `next` closure. So if catch some error, should also execute it. 245 | 246 | ```swift 247 | struct LoginMiddleware: Middleware { 248 | func on(_ store: Store, action: Action, next: @escaping (Action) -> Void) -> Disposable { 249 | switch action { 250 | case is LogInAction: 251 | store.dispatch(LoadingAction()) 252 | 253 | let request = URLRequest(url: URL(string: "YOUR_URL")!) 254 | return URLSession.shared.rx.data(request: request) 255 | .subscribe(onNext: { 256 | next(LoadedAction(data: $0)) 257 | }, onError: { 258 | next(LoadErrorAction(error: $0)) 259 | }) 260 | default: 261 | next(action) 262 | } 263 | 264 | return Disposables.create() 265 | } 266 | } 267 | ``` 268 | 269 | Multiple `Middleware` can be created. They are executed in the order they were created. 270 | 271 | ```swift 272 | let shared = Store(reducer: AppReducer(), state: AppState(), middlewares: LoggingMiddleware(), LoginMiddleware()) 273 | ``` 274 | 275 | ## LICENSE 276 | Under the MIT license. See LICENSE file for details. 277 | -------------------------------------------------------------------------------- /RxDucks.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'RxDucks' 3 | s.version = '0.2.0' 4 | s.swift_version = '5.0' 5 | s.summary = 'RxDucks is a Redux-like framework working on RxSwift.' 6 | s.homepage = 'https://github.com/cats-oss/RxDucks' 7 | s.license = { :type => 'MIT', :file => 'LICENSE' } 8 | s.author = { 'Kyohei Ito' => 'ito_kyohei@cyberagent.co.jp' } 9 | s.source = { :git => 'https://github.com/cats-oss/RxDucks.git', :tag => s.version.to_s } 10 | s.ios.deployment_target = '8.0' 11 | s.tvos.deployment_target = '9.0' 12 | s.osx.deployment_target = '10.10' 13 | s.watchos.deployment_target = '3.0' 14 | s.source_files = 'RxDucks/**/*.{h,swift}' 15 | s.requires_arc = true 16 | s.dependency "RxSwift", "~> 4.4" 17 | s.dependency "RxCocoa", "~> 4.4" 18 | end 19 | -------------------------------------------------------------------------------- /RxDucks.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C78AEB982100665F007DA210 /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7A4A1FD20F881510056FE96 /* RxCocoa.framework */; }; 11 | C78AEB992100665F007DA210 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7A4A1FC20F881500056FE96 /* RxSwift.framework */; }; 12 | C7A4A1FE20F881510056FE96 /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7A4A1FC20F881500056FE96 /* RxSwift.framework */; }; 13 | C7A4A1FF20F881510056FE96 /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7A4A1FD20F881510056FE96 /* RxCocoa.framework */; }; 14 | C7F1F26020F7972800683D5E /* RxDucks.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7F1F25620F7972800683D5E /* RxDucks.framework */; }; 15 | C7F1F26520F7972800683D5E /* RxDucksTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F26420F7972800683D5E /* RxDucksTests.swift */; }; 16 | C7F1F26720F7972800683D5E /* RxDucks.h in Headers */ = {isa = PBXBuildFile; fileRef = C7F1F25920F7972800683D5E /* RxDucks.h */; settings = {ATTRIBUTES = (Public, ); }; }; 17 | C7F1F27320F7A88700683D5E /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F27020F7A88600683D5E /* Action.swift */; }; 18 | C7F1F27420F7A88700683D5E /* Store.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F27120F7A88600683D5E /* Store.swift */; }; 19 | C7F1F27520F7A88700683D5E /* Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F27220F7A88700683D5E /* Reducer.swift */; }; 20 | C7F1F2BB20F7B03900683D5E /* Middleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F2BA20F7B03900683D5E /* Middleware.swift */; }; 21 | C7F1F2BD20F7B16D00683D5E /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F1F2BC20F7B16D00683D5E /* State.swift */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | C7F1F26120F7972800683D5E /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = C7F1F24D20F7972800683D5E /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = C7F1F25520F7972800683D5E; 30 | remoteInfo = RxDucks; 31 | }; 32 | /* End PBXContainerItemProxy section */ 33 | 34 | /* Begin PBXFileReference section */ 35 | C7A4A1FC20F881500056FE96 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/iOS/RxSwift.framework; sourceTree = ""; }; 36 | C7A4A1FD20F881510056FE96 /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = Carthage/Build/iOS/RxCocoa.framework; sourceTree = ""; }; 37 | C7CB4DE72101EBCE00E78CBF /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = Carthage/Build/Mac/RxCocoa.framework; sourceTree = ""; }; 38 | C7CB4DE82101EBCE00E78CBF /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/Mac/RxSwift.framework; sourceTree = ""; }; 39 | C7CB4DEC2102141E00E78CBF /* RxDucks.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = RxDucks.xcconfig; sourceTree = ""; }; 40 | C7F1F25620F7972800683D5E /* RxDucks.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxDucks.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | C7F1F25920F7972800683D5E /* RxDucks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RxDucks.h; sourceTree = ""; }; 42 | C7F1F25A20F7972800683D5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | C7F1F25F20F7972800683D5E /* RxDucksTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RxDucksTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | C7F1F26420F7972800683D5E /* RxDucksTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RxDucksTests.swift; sourceTree = ""; }; 45 | C7F1F26620F7972800683D5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | C7F1F27020F7A88600683D5E /* Action.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Action.swift; sourceTree = ""; }; 47 | C7F1F27120F7A88600683D5E /* Store.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Store.swift; sourceTree = ""; }; 48 | C7F1F27220F7A88700683D5E /* Reducer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reducer.swift; sourceTree = ""; }; 49 | C7F1F2AB20F7AD4300683D5E /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Example/Carthage/Build/iOS/RxSwift.framework; sourceTree = ""; }; 50 | C7F1F2AC20F7AD4400683D5E /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = Example/Carthage/Build/iOS/RxCocoa.framework; sourceTree = ""; }; 51 | C7F1F2BA20F7B03900683D5E /* Middleware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Middleware.swift; sourceTree = ""; }; 52 | C7F1F2BC20F7B16D00683D5E /* State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = State.swift; sourceTree = ""; }; 53 | /* End PBXFileReference section */ 54 | 55 | /* Begin PBXFrameworksBuildPhase section */ 56 | C7F1F25220F7972800683D5E /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | C7A4A1FE20F881510056FE96 /* RxSwift.framework in Frameworks */, 61 | C7A4A1FF20F881510056FE96 /* RxCocoa.framework in Frameworks */, 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | C7F1F25C20F7972800683D5E /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | C78AEB982100665F007DA210 /* RxCocoa.framework in Frameworks */, 70 | C78AEB992100665F007DA210 /* RxSwift.framework in Frameworks */, 71 | C7F1F26020F7972800683D5E /* RxDucks.framework in Frameworks */, 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | /* End PBXFrameworksBuildPhase section */ 76 | 77 | /* Begin PBXGroup section */ 78 | C7CB4DEB2102140F00E78CBF /* Support Files */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | C7CB4DEC2102141E00E78CBF /* RxDucks.xcconfig */, 82 | ); 83 | path = "Support Files"; 84 | sourceTree = ""; 85 | }; 86 | C7F1F24C20F7972800683D5E = { 87 | isa = PBXGroup; 88 | children = ( 89 | C7F1F25820F7972800683D5E /* RxDucks */, 90 | C7F1F26320F7972800683D5E /* RxDucksTests */, 91 | C7F1F25720F7972800683D5E /* Products */, 92 | C7F1F2AA20F7AD4300683D5E /* Frameworks */, 93 | C7CB4DEB2102140F00E78CBF /* Support Files */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | C7F1F25720F7972800683D5E /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | C7F1F25620F7972800683D5E /* RxDucks.framework */, 101 | C7F1F25F20F7972800683D5E /* RxDucksTests.xctest */, 102 | ); 103 | name = Products; 104 | sourceTree = ""; 105 | }; 106 | C7F1F25820F7972800683D5E /* RxDucks */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | C7F1F27020F7A88600683D5E /* Action.swift */, 110 | C7F1F25A20F7972800683D5E /* Info.plist */, 111 | C7F1F2BA20F7B03900683D5E /* Middleware.swift */, 112 | C7F1F27220F7A88700683D5E /* Reducer.swift */, 113 | C7F1F25920F7972800683D5E /* RxDucks.h */, 114 | C7F1F2BC20F7B16D00683D5E /* State.swift */, 115 | C7F1F27120F7A88600683D5E /* Store.swift */, 116 | ); 117 | path = RxDucks; 118 | sourceTree = ""; 119 | }; 120 | C7F1F26320F7972800683D5E /* RxDucksTests */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | C7F1F26420F7972800683D5E /* RxDucksTests.swift */, 124 | C7F1F26620F7972800683D5E /* Info.plist */, 125 | ); 126 | path = RxDucksTests; 127 | sourceTree = ""; 128 | }; 129 | C7F1F2AA20F7AD4300683D5E /* Frameworks */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | C7CB4DE72101EBCE00E78CBF /* RxCocoa.framework */, 133 | C7CB4DE82101EBCE00E78CBF /* RxSwift.framework */, 134 | C7A4A1FD20F881510056FE96 /* RxCocoa.framework */, 135 | C7A4A1FC20F881500056FE96 /* RxSwift.framework */, 136 | C7F1F2AC20F7AD4400683D5E /* RxCocoa.framework */, 137 | C7F1F2AB20F7AD4300683D5E /* RxSwift.framework */, 138 | ); 139 | name = Frameworks; 140 | sourceTree = ""; 141 | }; 142 | /* End PBXGroup section */ 143 | 144 | /* Begin PBXHeadersBuildPhase section */ 145 | C7F1F25320F7972800683D5E /* Headers */ = { 146 | isa = PBXHeadersBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | C7F1F26720F7972800683D5E /* RxDucks.h in Headers */, 150 | ); 151 | runOnlyForDeploymentPostprocessing = 0; 152 | }; 153 | /* End PBXHeadersBuildPhase section */ 154 | 155 | /* Begin PBXNativeTarget section */ 156 | C7F1F25520F7972800683D5E /* RxDucks */ = { 157 | isa = PBXNativeTarget; 158 | buildConfigurationList = C7F1F26A20F7972800683D5E /* Build configuration list for PBXNativeTarget "RxDucks" */; 159 | buildPhases = ( 160 | C7F1F25120F7972800683D5E /* Sources */, 161 | C7F1F25220F7972800683D5E /* Frameworks */, 162 | C7F1F25320F7972800683D5E /* Headers */, 163 | C7F1F25420F7972800683D5E /* Resources */, 164 | ); 165 | buildRules = ( 166 | ); 167 | dependencies = ( 168 | ); 169 | name = RxDucks; 170 | productName = RxDucks; 171 | productReference = C7F1F25620F7972800683D5E /* RxDucks.framework */; 172 | productType = "com.apple.product-type.framework"; 173 | }; 174 | C7F1F25E20F7972800683D5E /* RxDucksTests */ = { 175 | isa = PBXNativeTarget; 176 | buildConfigurationList = C7F1F26D20F7972800683D5E /* Build configuration list for PBXNativeTarget "RxDucksTests" */; 177 | buildPhases = ( 178 | C7F1F25B20F7972800683D5E /* Sources */, 179 | C7F1F25C20F7972800683D5E /* Frameworks */, 180 | C7F1F25D20F7972800683D5E /* Resources */, 181 | C78AEB9621005A90007DA210 /* Carthage */, 182 | ); 183 | buildRules = ( 184 | ); 185 | dependencies = ( 186 | C7F1F26220F7972800683D5E /* PBXTargetDependency */, 187 | ); 188 | name = RxDucksTests; 189 | productName = RxDucksTests; 190 | productReference = C7F1F25F20F7972800683D5E /* RxDucksTests.xctest */; 191 | productType = "com.apple.product-type.bundle.unit-test"; 192 | }; 193 | /* End PBXNativeTarget section */ 194 | 195 | /* Begin PBXProject section */ 196 | C7F1F24D20F7972800683D5E /* Project object */ = { 197 | isa = PBXProject; 198 | attributes = { 199 | LastSwiftUpdateCheck = 0930; 200 | LastUpgradeCheck = 0930; 201 | ORGANIZATIONNAME = "CyberAgent, Inc."; 202 | TargetAttributes = { 203 | C7F1F25520F7972800683D5E = { 204 | CreatedOnToolsVersion = 9.3.1; 205 | LastSwiftMigration = 0930; 206 | }; 207 | C7F1F25E20F7972800683D5E = { 208 | CreatedOnToolsVersion = 9.3.1; 209 | }; 210 | }; 211 | }; 212 | buildConfigurationList = C7F1F25020F7972800683D5E /* Build configuration list for PBXProject "RxDucks" */; 213 | compatibilityVersion = "Xcode 9.3"; 214 | developmentRegion = en; 215 | hasScannedForEncodings = 0; 216 | knownRegions = ( 217 | en, 218 | Base, 219 | ); 220 | mainGroup = C7F1F24C20F7972800683D5E; 221 | productRefGroup = C7F1F25720F7972800683D5E /* Products */; 222 | projectDirPath = ""; 223 | projectRoot = ""; 224 | targets = ( 225 | C7F1F25520F7972800683D5E /* RxDucks */, 226 | C7F1F25E20F7972800683D5E /* RxDucksTests */, 227 | ); 228 | }; 229 | /* End PBXProject section */ 230 | 231 | /* Begin PBXResourcesBuildPhase section */ 232 | C7F1F25420F7972800683D5E /* Resources */ = { 233 | isa = PBXResourcesBuildPhase; 234 | buildActionMask = 2147483647; 235 | files = ( 236 | ); 237 | runOnlyForDeploymentPostprocessing = 0; 238 | }; 239 | C7F1F25D20F7972800683D5E /* Resources */ = { 240 | isa = PBXResourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | /* End PBXResourcesBuildPhase section */ 247 | 248 | /* Begin PBXShellScriptBuildPhase section */ 249 | C78AEB9621005A90007DA210 /* Carthage */ = { 250 | isa = PBXShellScriptBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | ); 254 | inputPaths = ( 255 | "$(SRCROOT)/Carthage/Build/iOS/RxCocoa.framework", 256 | "$(SRCROOT)/Carthage/Build/iOS/RxSwift.framework", 257 | ); 258 | name = Carthage; 259 | outputPaths = ( 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | shellPath = /bin/sh; 263 | shellScript = "carthage copy-frameworks"; 264 | }; 265 | /* End PBXShellScriptBuildPhase section */ 266 | 267 | /* Begin PBXSourcesBuildPhase section */ 268 | C7F1F25120F7972800683D5E /* Sources */ = { 269 | isa = PBXSourcesBuildPhase; 270 | buildActionMask = 2147483647; 271 | files = ( 272 | C7F1F27320F7A88700683D5E /* Action.swift in Sources */, 273 | C7F1F2BB20F7B03900683D5E /* Middleware.swift in Sources */, 274 | C7F1F27420F7A88700683D5E /* Store.swift in Sources */, 275 | C7F1F2BD20F7B16D00683D5E /* State.swift in Sources */, 276 | C7F1F27520F7A88700683D5E /* Reducer.swift in Sources */, 277 | ); 278 | runOnlyForDeploymentPostprocessing = 0; 279 | }; 280 | C7F1F25B20F7972800683D5E /* Sources */ = { 281 | isa = PBXSourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | C7F1F26520F7972800683D5E /* RxDucksTests.swift in Sources */, 285 | ); 286 | runOnlyForDeploymentPostprocessing = 0; 287 | }; 288 | /* End PBXSourcesBuildPhase section */ 289 | 290 | /* Begin PBXTargetDependency section */ 291 | C7F1F26220F7972800683D5E /* PBXTargetDependency */ = { 292 | isa = PBXTargetDependency; 293 | target = C7F1F25520F7972800683D5E /* RxDucks */; 294 | targetProxy = C7F1F26120F7972800683D5E /* PBXContainerItemProxy */; 295 | }; 296 | /* End PBXTargetDependency section */ 297 | 298 | /* Begin XCBuildConfiguration section */ 299 | C7F1F26820F7972800683D5E /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | baseConfigurationReference = C7CB4DEC2102141E00E78CBF /* RxDucks.xcconfig */; 302 | buildSettings = { 303 | ALWAYS_SEARCH_USER_PATHS = NO; 304 | CLANG_ANALYZER_NONNULL = YES; 305 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 306 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 307 | CLANG_CXX_LIBRARY = "libc++"; 308 | CLANG_ENABLE_MODULES = YES; 309 | CLANG_ENABLE_OBJC_ARC = YES; 310 | CLANG_ENABLE_OBJC_WEAK = YES; 311 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 312 | CLANG_WARN_BOOL_CONVERSION = YES; 313 | CLANG_WARN_COMMA = YES; 314 | CLANG_WARN_CONSTANT_CONVERSION = YES; 315 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 316 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 317 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 318 | CLANG_WARN_EMPTY_BODY = YES; 319 | CLANG_WARN_ENUM_CONVERSION = YES; 320 | CLANG_WARN_INFINITE_RECURSION = YES; 321 | CLANG_WARN_INT_CONVERSION = YES; 322 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 323 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 324 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 325 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 326 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 327 | CLANG_WARN_STRICT_PROTOTYPES = YES; 328 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 329 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 330 | CLANG_WARN_UNREACHABLE_CODE = YES; 331 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 332 | CODE_SIGN_IDENTITY = "iPhone Developer"; 333 | COPY_PHASE_STRIP = NO; 334 | CURRENT_PROJECT_VERSION = 1; 335 | DEBUG_INFORMATION_FORMAT = dwarf; 336 | ENABLE_STRICT_OBJC_MSGSEND = YES; 337 | ENABLE_TESTABILITY = YES; 338 | GCC_C_LANGUAGE_STANDARD = gnu11; 339 | GCC_DYNAMIC_NO_PIC = NO; 340 | GCC_NO_COMMON_BLOCKS = YES; 341 | GCC_OPTIMIZATION_LEVEL = 0; 342 | GCC_PREPROCESSOR_DEFINITIONS = ( 343 | "DEBUG=1", 344 | "$(inherited)", 345 | ); 346 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 347 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 348 | GCC_WARN_UNDECLARED_SELECTOR = YES; 349 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 350 | GCC_WARN_UNUSED_FUNCTION = YES; 351 | GCC_WARN_UNUSED_VARIABLE = YES; 352 | MTL_ENABLE_DEBUG_INFO = YES; 353 | ONLY_ACTIVE_ARCH = YES; 354 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 355 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 356 | VERSIONING_SYSTEM = "apple-generic"; 357 | VERSION_INFO_PREFIX = ""; 358 | }; 359 | name = Debug; 360 | }; 361 | C7F1F26920F7972800683D5E /* Release */ = { 362 | isa = XCBuildConfiguration; 363 | baseConfigurationReference = C7CB4DEC2102141E00E78CBF /* RxDucks.xcconfig */; 364 | buildSettings = { 365 | ALWAYS_SEARCH_USER_PATHS = NO; 366 | CLANG_ANALYZER_NONNULL = YES; 367 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 368 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 369 | CLANG_CXX_LIBRARY = "libc++"; 370 | CLANG_ENABLE_MODULES = YES; 371 | CLANG_ENABLE_OBJC_ARC = YES; 372 | CLANG_ENABLE_OBJC_WEAK = YES; 373 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 374 | CLANG_WARN_BOOL_CONVERSION = YES; 375 | CLANG_WARN_COMMA = YES; 376 | CLANG_WARN_CONSTANT_CONVERSION = YES; 377 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 378 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 379 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 380 | CLANG_WARN_EMPTY_BODY = YES; 381 | CLANG_WARN_ENUM_CONVERSION = YES; 382 | CLANG_WARN_INFINITE_RECURSION = YES; 383 | CLANG_WARN_INT_CONVERSION = YES; 384 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 385 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 386 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 387 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 388 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 389 | CLANG_WARN_STRICT_PROTOTYPES = YES; 390 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 391 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 392 | CLANG_WARN_UNREACHABLE_CODE = YES; 393 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 394 | CODE_SIGN_IDENTITY = "iPhone Developer"; 395 | COPY_PHASE_STRIP = NO; 396 | CURRENT_PROJECT_VERSION = 1; 397 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 398 | ENABLE_NS_ASSERTIONS = NO; 399 | ENABLE_STRICT_OBJC_MSGSEND = YES; 400 | GCC_C_LANGUAGE_STANDARD = gnu11; 401 | GCC_NO_COMMON_BLOCKS = YES; 402 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 403 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 404 | GCC_WARN_UNDECLARED_SELECTOR = YES; 405 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 406 | GCC_WARN_UNUSED_FUNCTION = YES; 407 | GCC_WARN_UNUSED_VARIABLE = YES; 408 | MTL_ENABLE_DEBUG_INFO = NO; 409 | SWIFT_COMPILATION_MODE = wholemodule; 410 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 411 | VALIDATE_PRODUCT = YES; 412 | VERSIONING_SYSTEM = "apple-generic"; 413 | VERSION_INFO_PREFIX = ""; 414 | }; 415 | name = Release; 416 | }; 417 | C7F1F26B20F7972800683D5E /* Debug */ = { 418 | isa = XCBuildConfiguration; 419 | buildSettings = { 420 | CLANG_ENABLE_MODULES = YES; 421 | CODE_SIGN_IDENTITY = ""; 422 | CODE_SIGN_STYLE = Automatic; 423 | DEFINES_MODULE = YES; 424 | DYLIB_COMPATIBILITY_VERSION = 1; 425 | DYLIB_CURRENT_VERSION = 1; 426 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 427 | INFOPLIST_FILE = RxDucks/Info.plist; 428 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 429 | LD_RUNPATH_SEARCH_PATHS = ( 430 | "$(inherited)", 431 | "@executable_path/Frameworks", 432 | "@loader_path/Frameworks", 433 | ); 434 | PRODUCT_BUNDLE_IDENTIFIER = jp.co.cyberagent.RxDucks; 435 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 436 | SKIP_INSTALL = YES; 437 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 438 | }; 439 | name = Debug; 440 | }; 441 | C7F1F26C20F7972800683D5E /* Release */ = { 442 | isa = XCBuildConfiguration; 443 | buildSettings = { 444 | CLANG_ENABLE_MODULES = YES; 445 | CODE_SIGN_IDENTITY = ""; 446 | CODE_SIGN_STYLE = Automatic; 447 | DEFINES_MODULE = YES; 448 | DYLIB_COMPATIBILITY_VERSION = 1; 449 | DYLIB_CURRENT_VERSION = 1; 450 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 451 | INFOPLIST_FILE = RxDucks/Info.plist; 452 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 453 | LD_RUNPATH_SEARCH_PATHS = ( 454 | "$(inherited)", 455 | "@executable_path/Frameworks", 456 | "@loader_path/Frameworks", 457 | ); 458 | PRODUCT_BUNDLE_IDENTIFIER = jp.co.cyberagent.RxDucks; 459 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 460 | SKIP_INSTALL = YES; 461 | }; 462 | name = Release; 463 | }; 464 | C7F1F26E20F7972800683D5E /* Debug */ = { 465 | isa = XCBuildConfiguration; 466 | buildSettings = { 467 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 468 | CODE_SIGN_STYLE = Automatic; 469 | INFOPLIST_FILE = RxDucksTests/Info.plist; 470 | LD_RUNPATH_SEARCH_PATHS = ( 471 | "$(inherited)", 472 | "@executable_path/Frameworks", 473 | "@loader_path/Frameworks", 474 | ); 475 | PRODUCT_BUNDLE_IDENTIFIER = jp.co.cyberagent.RxDucksTests; 476 | PRODUCT_NAME = "$(TARGET_NAME)"; 477 | }; 478 | name = Debug; 479 | }; 480 | C7F1F26F20F7972800683D5E /* Release */ = { 481 | isa = XCBuildConfiguration; 482 | buildSettings = { 483 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 484 | CODE_SIGN_STYLE = Automatic; 485 | INFOPLIST_FILE = RxDucksTests/Info.plist; 486 | LD_RUNPATH_SEARCH_PATHS = ( 487 | "$(inherited)", 488 | "@executable_path/Frameworks", 489 | "@loader_path/Frameworks", 490 | ); 491 | PRODUCT_BUNDLE_IDENTIFIER = jp.co.cyberagent.RxDucksTests; 492 | PRODUCT_NAME = "$(TARGET_NAME)"; 493 | }; 494 | name = Release; 495 | }; 496 | /* End XCBuildConfiguration section */ 497 | 498 | /* Begin XCConfigurationList section */ 499 | C7F1F25020F7972800683D5E /* Build configuration list for PBXProject "RxDucks" */ = { 500 | isa = XCConfigurationList; 501 | buildConfigurations = ( 502 | C7F1F26820F7972800683D5E /* Debug */, 503 | C7F1F26920F7972800683D5E /* Release */, 504 | ); 505 | defaultConfigurationIsVisible = 0; 506 | defaultConfigurationName = Release; 507 | }; 508 | C7F1F26A20F7972800683D5E /* Build configuration list for PBXNativeTarget "RxDucks" */ = { 509 | isa = XCConfigurationList; 510 | buildConfigurations = ( 511 | C7F1F26B20F7972800683D5E /* Debug */, 512 | C7F1F26C20F7972800683D5E /* Release */, 513 | ); 514 | defaultConfigurationIsVisible = 0; 515 | defaultConfigurationName = Release; 516 | }; 517 | C7F1F26D20F7972800683D5E /* Build configuration list for PBXNativeTarget "RxDucksTests" */ = { 518 | isa = XCConfigurationList; 519 | buildConfigurations = ( 520 | C7F1F26E20F7972800683D5E /* Debug */, 521 | C7F1F26F20F7972800683D5E /* Release */, 522 | ); 523 | defaultConfigurationIsVisible = 0; 524 | defaultConfigurationName = Release; 525 | }; 526 | /* End XCConfigurationList section */ 527 | }; 528 | rootObject = C7F1F24D20F7972800683D5E /* Project object */; 529 | } 530 | -------------------------------------------------------------------------------- /RxDucks.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RxDucks.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RxDucks.xcodeproj/xcshareddata/xcschemes/RxDucks.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | 54 | 55 | 65 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 84 | 90 | 91 | 92 | 93 | 95 | 96 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /RxDucks.xcodeproj/xcshareddata/xcschemes/RxDucksTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 16 | 18 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 40 | 41 | 42 | 43 | 49 | 50 | 52 | 53 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /RxDucks/Action.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Action.swift 3 | // RxDucks 4 | // 5 | // Created by Kyohei Ito on 2017/10/20. 6 | // Copyright © 2017年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | /// change of Action is notified to the state the store has. 10 | public protocol Action {} 11 | 12 | /// change of IgnorableAction is not notified to the state the store has. 13 | public protocol IgnorableAction: Action {} 14 | 15 | public final class ActionCreator { 16 | public init() {} 17 | } 18 | -------------------------------------------------------------------------------- /RxDucks/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /RxDucks/Middleware.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Middleware.swift 3 | // RxDucks 4 | // 5 | // Created by Kyohei Ito on 2018/07/13. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import RxSwift 10 | 11 | public protocol MiddlewareType { 12 | /// the function does not have to override. Please use the function of the store that the middleware has, with the state specified. 13 | func on(_ store: StoreType, action: Action, next: @escaping (Action) -> Void) -> Disposable 14 | } 15 | 16 | public protocol Middleware: MiddlewareType { 17 | associatedtype State: StateType 18 | 19 | /// execute next action according to the input action. 20 | func on(_ store: Store, action: Action, next: @escaping (Action) -> Void) -> Disposable 21 | } 22 | 23 | extension Middleware { 24 | public func on(_ store: StoreType, action: Action, next: @escaping (Action) -> Void) -> Disposable { 25 | if let store = store as? Store { 26 | return on(store, action: action, next: next) 27 | } 28 | next(action) 29 | return Disposables.create() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /RxDucks/Reducer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Reducer.swift 3 | // SuperChoice 4 | // 5 | // Created by Kyohei Ito on 2017/10/20. 6 | // Copyright © 2017年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import RxSwift 10 | 11 | public protocol Reducer { 12 | associatedtype State: StateType 13 | 14 | /// mutates an input state to an output state according to the action. 15 | func reduce(_ state: State, action: Action) -> State 16 | } 17 | -------------------------------------------------------------------------------- /RxDucks/RxDucks.h: -------------------------------------------------------------------------------- 1 | // 2 | // RxDucks.h 3 | // RxDucks 4 | // 5 | // Created by Kyohei Ito on 2018/07/12. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for RxDucks. 12 | FOUNDATION_EXPORT double RxDucksVersionNumber; 13 | 14 | //! Project version string for RxDucks. 15 | FOUNDATION_EXPORT const unsigned char RxDucksVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /RxDucks/State.swift: -------------------------------------------------------------------------------- 1 | // 2 | // State.swift 3 | // RxDucks 4 | // 5 | // Created by Kyohei Ito on 2018/07/13. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | public protocol StateType {} 10 | 11 | public typealias State = StateType 12 | -------------------------------------------------------------------------------- /RxDucks/Store.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Store.swift 3 | // SuperChoice 4 | // 5 | // Created by Kyohei Ito on 2017/10/20. 6 | // Copyright © 2017年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import RxSwift 10 | import RxCocoa 11 | 12 | public protocol StoreType {} 13 | 14 | open class Store: StoreType { 15 | private let disposeBag = DisposeBag() 16 | private let _state: BehaviorRelay 17 | private let _action = PublishRelay() 18 | private let _dispatcher = PublishRelay() 19 | private var _newState: Observable { 20 | return _state.skip(1) 21 | } 22 | 23 | /// the current state the store has 24 | public var currentState: State { 25 | return _state.value 26 | } 27 | 28 | /// Observable that sends changed elements and current element. 29 | /// IgnorableAction changes are not notified. 30 | /// it doesn't terminate with error or completed. 31 | public var state: Observable { 32 | return newState 33 | .startWith(_state.value) 34 | } 35 | 36 | /// Observable that only sends changed elements, ignoring current element. 37 | /// IgnorableAction changes are not notified. 38 | /// it doesn't terminate with error or completed. 39 | public var newState: Observable { 40 | return Observable.zip(_action, _newState) 41 | .flatMap { action, state -> Observable in 42 | if action is IgnorableAction { 43 | return .empty() 44 | } 45 | return .just(state) 46 | } 47 | } 48 | 49 | /// Binder that dispatch an action. 50 | public var dispatcher: Binder { 51 | return Binder(self, scheduler: CurrentThreadScheduler.instance) { me, type in 52 | me.dispatch(type) 53 | } 54 | } 55 | 56 | /// Dispatch an action through the middlewares and the reducers to mutate the state. 57 | /// - Parameter action: the action that will be through the middlewares and the reducers. 58 | public func dispatch(_ action: Action) { 59 | _dispatcher.accept(action) 60 | } 61 | 62 | /// initialize the Store. 63 | /// - Parameter reducer: the reducer to be executed by the dispatcher. 64 | /// - Parameter state: the initial state. 65 | /// - Parameter middlewares: the middlewares of Variadic Parameters to be executed by the dispatcher. 66 | public convenience init(reducer: R, state: State, middlewares: MiddlewareType...) where R.State == State { 67 | self.init(reducer: reducer, state: state, middlewares: middlewares as [MiddlewareType]) 68 | } 69 | 70 | /// initialize the Store. 71 | /// - Parameter reducer: the reducer to be executed by the dispatcher. 72 | /// - Parameter state: the initial state. 73 | /// - Parameter middlewares: the middlewares of Array to be executed by the dispatcher. 74 | public init(reducer: R, state: State, middlewares: [MiddlewareType]) where R.State == State { 75 | _state = BehaviorRelay(value: state) 76 | 77 | let actionState: Observable<(Action, State)> = _dispatcher 78 | .flatMap { [weak self] action -> Observable in 79 | guard let me = self else { return .empty() } 80 | 81 | return middlewares.reduce(.just(action)) { observable, middleware in 82 | observable.flatMap { action in 83 | return Observable.create { observer in 84 | return middleware.on(me, action: action) { action in 85 | observer.onNext(action) 86 | observer.onCompleted() 87 | } 88 | } 89 | } 90 | } 91 | } 92 | .withLatestFrom(_state) { action, state in 93 | (action, reducer.reduce(state, action: action)) 94 | } 95 | .share() 96 | 97 | actionState 98 | .map { $0.0 } 99 | .bind(to: _action) 100 | .disposed(by: disposeBag) 101 | 102 | actionState 103 | .map { $0.1 } 104 | .bind(to: _state) 105 | .disposed(by: disposeBag) 106 | } 107 | } 108 | 109 | extension Store { 110 | /// Specific element avoiding duplicate notifications. 111 | /// IgnorableAction changes are not notified. 112 | /// - Parameter selector: the closure that allows to extract an Element 113 | /// - Returns: an Observable of the Element 114 | public func specifyState(_ selector: @escaping (State) -> E) -> Observable where E: Equatable { 115 | return state 116 | .map(selector) 117 | .distinctUntilChanged() 118 | } 119 | 120 | /// Specific element avoiding duplicate notifications, ignoring current element. 121 | /// IgnorableAction changes are not notified. 122 | /// - Parameter selector: the closure that allows to extract an Element 123 | /// - Returns: an Observable of the Element 124 | public func specifyNewState(_ selector: @escaping (State) -> E) -> Observable where E: Equatable { 125 | return specifyState(selector) 126 | .skip(1) 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /RxDucksTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /RxDucksTests/RxDucksTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RxDucksTests.swift 3 | // RxDucksTests 4 | // 5 | // Created by Kyohei Ito on 2018/07/12. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import RxDucks 11 | import RxSwift 12 | import RxCocoa 13 | 14 | class RxDucksTests: XCTestCase { 15 | var disposeBag = DisposeBag() 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | disposeBag = DisposeBag() 24 | } 25 | 26 | func testInitialize() { 27 | let state = TestState(int: 10, string: "test") 28 | let store1 = Store(reducer: TestReducer(), state: state) 29 | XCTAssertEqual(store1.currentState.int, 10) 30 | XCTAssertEqual(store1.currentState.string, "test") 31 | 32 | let store2 = Store(reducer: TestReducer(), state: state, middlewares: []) 33 | XCTAssertEqual(store2.currentState.int, 10) 34 | XCTAssertEqual(store2.currentState.string, "test") 35 | } 36 | 37 | func testState() { 38 | let state = BehaviorRelay(value: nil) 39 | let store = Store(reducer: TestReducer(), state: TestState(), middlewares: TestMiddleware()) 40 | store.state 41 | .bind(to: state) 42 | .disposed(by: disposeBag) 43 | 44 | XCTAssertEqual(state.value?.int, 0) 45 | XCTAssertEqual(state.value?.string, "") 46 | 47 | store.dispatch(TestAction(int: 5, string: "A")) 48 | 49 | XCTAssertEqual(state.value?.int, 5) 50 | XCTAssertEqual(state.value?.string, "A") 51 | 52 | store.dispatch(IgnoreAction(int: 10, string: "B")) 53 | 54 | XCTAssertEqual(state.value?.int, 5) 55 | XCTAssertEqual(state.value?.string, "A") 56 | 57 | XCTAssertEqual(store.currentState.int, 10) 58 | XCTAssertEqual(store.currentState.string, "B") 59 | } 60 | 61 | func testNewState() { 62 | let state = BehaviorRelay(value: nil) 63 | let store = Store(reducer: TestReducer(), state: TestState(), middlewares: TestMiddleware()) 64 | store.newState 65 | .bind(to: state) 66 | .disposed(by: disposeBag) 67 | 68 | XCTAssertNil(state.value?.int) 69 | XCTAssertNil(state.value?.string) 70 | 71 | store.dispatch(TestAction(int: 5, string: "A")) 72 | 73 | XCTAssertEqual(state.value?.int, 5) 74 | XCTAssertEqual(state.value?.string, "A") 75 | 76 | store.dispatch(IgnoreAction(int: 10, string: "B")) 77 | 78 | XCTAssertEqual(state.value?.int, 5) 79 | XCTAssertEqual(state.value?.string, "A") 80 | 81 | XCTAssertEqual(store.currentState.int, 10) 82 | XCTAssertEqual(store.currentState.string, "B") 83 | } 84 | 85 | func testSpecifyState() { 86 | let int = BehaviorRelay(value: nil) 87 | let string = BehaviorRelay(value: nil) 88 | let store = Store(reducer: TestReducer(), state: TestState(), middlewares: TestMiddleware()) 89 | 90 | store 91 | .specifyState { $0.int } 92 | .bind(to: int) 93 | .disposed(by: disposeBag) 94 | 95 | store 96 | .specifyState { $0.string } 97 | .bind(to: string) 98 | .disposed(by: disposeBag) 99 | 100 | XCTAssertEqual(int.value, 0) 101 | XCTAssertEqual(string.value, "") 102 | 103 | store.dispatch(TestAction(int: 5, string: "A")) 104 | 105 | XCTAssertEqual(int.value, 5) 106 | XCTAssertEqual(string.value, "A") 107 | 108 | store.dispatch(TestAction(int: 10, string: "A")) 109 | 110 | XCTAssertEqual(int.value, 10) 111 | XCTAssertEqual(string.value, "A") 112 | 113 | int.accept(nil) 114 | string.accept(nil) 115 | 116 | store.dispatch(TestAction(int: 10, string: "A")) 117 | 118 | XCTAssertNil(int.value) 119 | XCTAssertNil(string.value) 120 | 121 | XCTAssertEqual(store.currentState.int, 10) 122 | XCTAssertEqual(store.currentState.string, "A") 123 | 124 | store.dispatch(IgnoreAction(int: 10, string: "B")) 125 | 126 | XCTAssertNil(int.value) 127 | XCTAssertNil(string.value) 128 | 129 | XCTAssertEqual(store.currentState.int, 10) 130 | XCTAssertEqual(store.currentState.string, "B") 131 | } 132 | 133 | func testSpecifyNewState() { 134 | let int = BehaviorRelay(value: nil) 135 | let string = BehaviorRelay(value: nil) 136 | let store = Store(reducer: TestReducer(), state: TestState(), middlewares: TestMiddleware()) 137 | 138 | store 139 | .specifyNewState { $0.int } 140 | .bind(to: int) 141 | .disposed(by: disposeBag) 142 | 143 | store 144 | .specifyNewState { $0.string } 145 | .bind(to: string) 146 | .disposed(by: disposeBag) 147 | 148 | XCTAssertNil(int.value) 149 | XCTAssertNil(string.value) 150 | 151 | store.dispatch(TestAction(int: 5, string: "A")) 152 | 153 | XCTAssertEqual(int.value, 5) 154 | XCTAssertEqual(string.value, "A") 155 | 156 | store.dispatch(TestAction(int: 10, string: "A")) 157 | 158 | XCTAssertEqual(int.value, 10) 159 | XCTAssertEqual(string.value, "A") 160 | 161 | int.accept(nil) 162 | string.accept(nil) 163 | 164 | store.dispatch(TestAction(int: 10, string: "A")) 165 | 166 | XCTAssertNil(int.value) 167 | XCTAssertNil(string.value) 168 | 169 | XCTAssertEqual(store.currentState.int, 10) 170 | XCTAssertEqual(store.currentState.string, "A") 171 | 172 | store.dispatch(IgnoreAction(int: 10, string: "B")) 173 | 174 | XCTAssertNil(int.value) 175 | XCTAssertNil(string.value) 176 | 177 | XCTAssertEqual(store.currentState.int, 10) 178 | XCTAssertEqual(store.currentState.string, "B") 179 | } 180 | 181 | func testActionCreator() { 182 | XCTAssertEqual(ActionCreator().ignore(10, "A"), IgnoreAction(int: 10, string: "A")) 183 | XCTAssertEqual(ActionCreator().test(10, "A"), TestAction(int: 10, string: "A")) 184 | } 185 | 186 | func testMiddleware() { 187 | let middleware1 = TestMiddleware() 188 | let middleware2 = TestMiddleware() 189 | let middleware3 = TestMiddleware() 190 | let store = Store(reducer: TestReducer(), state: TestState(), middlewares: middleware1, middleware2, middleware3) 191 | store.dispatch(IncreaseAction(count: 0)) 192 | 193 | XCTAssertEqual(middleware1.count, 1) 194 | XCTAssertEqual(middleware2.count, 2) 195 | XCTAssertEqual(middleware3.count, 3) 196 | } 197 | 198 | func testMiddlewareType() { 199 | struct A: Action, Equatable {} 200 | struct S: State {} 201 | struct R: Reducer { 202 | func reduce(_ state: S, action: Action) -> S { 203 | return S() 204 | } 205 | } 206 | struct M: Middleware { 207 | func on(_ store: Store, action: Action, next: @escaping (Action) -> Void) -> Disposable { 208 | next(A()) 209 | return Disposables.create() 210 | } 211 | } 212 | 213 | _ = M().on(Store(reducer: R(), state: S()), action: TestAction(int: 0, string: "")) { action in 214 | XCTAssertEqual(action as? A, A()) 215 | } 216 | 217 | _ = M().on(Store(reducer: TestReducer(), state: TestState()), action: TestAction(int: 0, string: "")) { action in 218 | XCTAssertNotEqual(action as? A, A()) 219 | } 220 | } 221 | 222 | func testDispatcher() { 223 | let state = BehaviorRelay(value: nil) 224 | let store = Store(reducer: TestReducer(), state: TestState(), middlewares: TestMiddleware()) 225 | store.state 226 | .bind(to: state) 227 | .disposed(by: disposeBag) 228 | 229 | XCTAssertEqual(state.value?.int, 0) 230 | XCTAssertEqual(state.value?.string, "") 231 | 232 | store.dispatch(TestAction(int: 5, string: "A")) 233 | 234 | XCTAssertEqual(state.value?.int, 5) 235 | XCTAssertEqual(state.value?.string, "A") 236 | 237 | store.dispatcher.onNext(TestAction(int: 10, string: "B")) 238 | 239 | XCTAssertEqual(store.currentState.int, 10) 240 | XCTAssertEqual(store.currentState.string, "B") 241 | } 242 | } 243 | 244 | class TestMiddleware: Middleware { 245 | var count = 0 246 | func on(_ store: Store, action: Action, next: @escaping (Action) -> Void) -> Disposable { 247 | switch action { 248 | case let action as IncreaseAction: 249 | count = action.count + 1 250 | next(IncreaseAction(count: count)) 251 | default: 252 | next(action) 253 | } 254 | 255 | return Disposables.create() 256 | } 257 | } 258 | 259 | extension ActionCreator { 260 | func ignore(_ int: Int, _ string: String) -> IgnoreAction { 261 | return IgnoreAction(int: int, string: string) 262 | } 263 | 264 | func test(_ int: Int, _ string: String) -> TestAction { 265 | return TestAction(int: int, string: string) 266 | } 267 | } 268 | 269 | struct IncreaseAction: Action { 270 | let count: Int 271 | } 272 | 273 | struct IgnoreAction: IgnorableAction, Equatable { 274 | let int: Int 275 | let string: String 276 | } 277 | 278 | struct TestAction: Action, Equatable { 279 | let int: Int 280 | let string: String 281 | } 282 | 283 | struct TestState: State, Equatable { 284 | var int = 0 285 | var string = "" 286 | } 287 | 288 | class TestReducer: Reducer { 289 | func reduce(_ state: TestState, action: Action) -> TestState { 290 | switch action { 291 | case let action as TestAction: 292 | return TestState(int: action.int, string: action.string) 293 | case let action as IgnoreAction: 294 | return TestState(int: action.int, string: action.string) 295 | default: 296 | return TestState() 297 | } 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /Support Files/RxDucks.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // RxDucks.xcconfig 3 | // RxDucks 4 | // 5 | // Created by Kyohei Ito on 2018/07/20. 6 | // Copyright © 2018年 CyberAgent, Inc. All rights reserved. 7 | // 8 | SWIFT_VERSION = 5.0 9 | IPHONEOS_DEPLOYMENT_TARGET = 8.0 10 | MACOSX_DEPLOYMENT_TARGET = 10.10 11 | TVOS_DEPLOYMENT_TARGET = 9.0 12 | WATCHOS_DEPLOYMENT_TARGET = 2.0 13 | 14 | SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator watchos watchsimulator appletvos appletvsimulator 15 | TARGETED_DEVICE_FAMILY = 1,2,3,4 16 | 17 | FRAMEWORK_SEARCH_PATHS[sdk=macosx*] = $(inherited) $(PROJECT_DIR)/Carthage/Build/Mac 18 | FRAMEWORK_SEARCH_PATHS[sdk=iphone*] = $(inherited) $(PROJECT_DIR)/Carthage/Build/iOS 19 | FRAMEWORK_SEARCH_PATHS[sdk=watch*] = $(inherited) $(PROJECT_DIR)/Carthage/Build/watchOS 20 | FRAMEWORK_SEARCH_PATHS[sdk=appletv*] = $(inherited) $(PROJECT_DIR)/Carthage/Build/tvOS 21 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "Carthage" 3 | - "Example" 4 | - "RxDucksTests" 5 | - "Support Files" 6 | --------------------------------------------------------------------------------