-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to use Effect.promise with Firebase's DynamicLinkComponents.shortenURL #94
Comments
Here's my code for reference : let shortLinkMiddleware = EffectMiddleware<DynamicLinkAction, DynamicLinkAction, AppState, DynamicLinkComponents>.onAction { action, context, getState in
let logger = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "ShortLinkMiddleware")
switch action {
case .generate:
return .promise(
token: "Any Hashable. Use this to cancel tasks, or to avoid two tasks of the same type",
perform: { context, completionblock in
os_log(
"Creating new short link...",
log: logger,
type: .debug
)
let state = getState()
let api = context.dependencies
if let link = URL(string: state.invitationDeepLink),
let bundleid = state.bundleID {
api.link = link
api.domain = state.universalLinkBaseURL
api.options = DynamicLinkComponentsOptions()
api.options?.pathLength = .unguessable
api.iOSParameters = DynamicLinkIOSParameters(bundleID: bundleid)
if let longDynamicLink = api.url {
DynamicLinkComponents.shortenURL(
longDynamicLink,
options: api.options,
completion: { url, warnings, error in
if let url = url {
completionblock(.response(url.absoluteString))
} else {
os_log(
"Error shortening the URL from : %s",
log: logger,
type: .debug,
String(describing: api.url)
)
completionblock(.error("Got an error while coverting short url"))
}
}
)
} else {
completionblock(.error("Hmmm... No long URL available."))
}
} else {
os_log(
"Error converting the deep link or bundleid...",
log: logger,
type: .debug
)
completionblock(.error("Got an error while converting short url"))
}
}
)
default: return .doNothing
}
} |
You are right. I didn't look yet with more time but it seems that https://github.com/SwiftRex/SwiftRex/blob/develop/Sources/CombineRex/Effect/Effect.swift#L191 is missing a CombineRex, RxSwiftRex and ReactiveSwiftRex, I couldn't find a way to write one single Effect to rule them all (yet), so there's a bit of duplication unfortunately. |
Seems to fix the compilation issue. Testing it out right now. |
* FIX : added escaping clause as discussed in issue #94 #94 (comment) * Added fix for RxSwift and ReactiveSwift implementations.
* FIX : added escaping clause as discussed in issue #94 #94 (comment) * Added fix for RxSwift and ReactiveSwift implementations.
Ok, v0.8.1 Release created, pushing Pods right now. |
I have been trying to use the EffectMiddleware, since it's now available in 0.8.0, as a way to build a quick Middleware to help generating short URLs for Firebase's DynamicLinks, via the Firebase iOS SDK. This seemed like the prototypical use for EffectMiddleware.
The shortenURL(_:options:completion:) (or shorten(completion:)) takes a completion block that gets called when the network call to get the short URL returns.
So I thought I could call Effect.promise's completion from there.
But apparently not :
So is there a better way to use EffectMiddleware to accommodate the escaping closure ? Should I not be using .promise ? @luizmb ?
The text was updated successfully, but these errors were encountered: