Skip to content

Instantly share code, notes, and snippets.

@nomothetis
Created March 27, 2015 15:21
Show Gist options
  • Save nomothetis/ff0399ccf442998e0151 to your computer and use it in GitHub Desktop.
Save nomothetis/ff0399ccf442998e0151 to your computer and use it in GitHub Desktop.
publc func createLoginproducer(username:String,
password:String) -> SignalProducer<UserState, LoginError> {
// Define processor here.
return createInternalLoginProducer(username:username, password:password, loginStateProcessor:determineLoginStateTest, userStateProcessor:determineUserStateTest)
}
public func createInternalLoginProducer(username : String,
password : String,
loginState : (String, String, (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> ())->(),
userState : (String, (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?)->Void) -> ())
-> SignalProducer<UserState, LoginError> {
return SignalProducer { sink, disposable in
func process(request : NSURLRequest, response : NSHTTPURLResponse?, data : AnyObject?, error : NSError?) {
switch processResponseWithData(response, data, error) {
case .Success(let box) :
sendNext(sink, box.unbox)
case .Failure(let e) :
sendError(sink, e.unbox)
}
}
loginState(username, password, process)
} |> tryMap(validateServerError) |> tryMap(validateLogin) |> tryMap(parseLoginJSON) |> joinMap(.Concat, createUserInformationProducer) |> tryMap(userState) |> mapError(loginErrorFromStoreError)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment