You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
Sample code in README causes compile error.
I test with Harvest v0.3.0 (Xcode 13.1) using new blank mac app.
// compile error: Generic type 'EffectMapping' specialized with too few type parameters (got 2, but expected 3)
typealiasEffectMapping=Harvester.EffectMapping<EffectQueue,EffectID>
// 'Effect' is not a member type of generic class 'MyApp.Harvester' (aka 'Harvester<Input, State>')
typealiasEffect=Harvester.Effect<Input,EffectQueue,EffectID>
Full source code:
import Harvest
import Combine
// 1. Define `State`s and `Input`s.
enumState{case loggedOut, loggingIn, loggedIn, loggingOut
}enumInput{case login, loginOK, logout, logoutOK
case forceLogout
}enumEffectQueue:EffectQueueProtocol{case `default`
case request
varflattenStrategy:FlattenStrategy{
switch self{case.default:return.merge
case.request:return.latest
}}staticvardefaultEffectQueue:EffectQueue{.default
}}
// NOTE: `EffectID` is useful for manual effect cancellation, but not used in this example.
typealiasEffectID=NevertypealiasHarvester=Harvest.Harvester<Input,State>typealiasEffectMapping=Harvester.EffectMapping<EffectQueue,EffectID>typealiasEffect=Harvester.Effect<Input,EffectQueue,EffectID>
// Additional effects while state-transitioning.
letloginOKPublisher=Just(()) /* show UI, setup DB, request APIs, ..., and send `Input.loginOK` */
letlogoutOKPublisher=Just(()) /* show UI, clear cache, cancel APIs, ..., and send `Input.logoutOK` */
letforceLogoutOKPublisher=Just(()) /* do something more special, ..., and send `Input.logoutOK` */
letcanForceLogout:(State)->Bool=[.loggingIn,.loggedIn].contains
letmappings:[EffectMapping]=[
/* Input | fromState => toState | Effect */
/* ----------------------------------------------------------*/
.login | .loggedOut =>.loggingIn | Effect(loginOKPublisher, queue:.request),.loginOK | .loggingIn =>.loggedIn | .empty,.logout | .loggedIn =>.loggingOut | Effect(logoutOKPublisher, queue:.request),.logoutOK | .loggingOut =>.loggedOut | .empty,.forceLogout | canForceLogout =>.loggingOut | Effect(forceLogoutOKPublisher, queue:.request)]
Sample code in README causes compile error.
I test with Harvest v0.3.0 (Xcode 13.1) using new blank mac app.
Full source code:
https://github.com/inamiy/Harvest/tree/0.3.0#3-create-effectmapping-effect-wise-reducer
The text was updated successfully, but these errors were encountered: