Share
Embed
Transcript
18 slides
-
Effect View Store DI Environment TCA ( The Composable Architecture
)ͱ w J04ΞϓϦ։ൃͷͨΊͷ3FEVY෩ ຯͳ044 w "QQMFͷެࣜϦΞΫςΟϒϓϩά ϥϛϯάϑϨʔϜϫʔΫͰ͋Δ $PNCJOFΛར༻͍ͯ͠Δ Reducerʢؔʣ State Action Combine @Published Combine Publisher -
v0.19.0 w FOVNͳ4UBUFʹରԠ͢ΔDBTFQBUIͷ 3FEVDFSQVMMCBDL͕Ճ w FOVNͳ4UBUFΛݸʑͷ4UBUFʹม͢Δ 4XJUDI4UPSFͷՃ w & ff
FDUUJNFS͕DBODFM*O'MJHIUUSVFΛݺͼग़ͤΔΑ ͏ʹͳΓɺࣗಈతʹDBODFMMBCMFJE͕ಉ͡ͳΒ DBODFMͰ͖Δɻ w 'PS&BDI4UPSF͕վྑ -
public enum AppState: Equatable { case login(LoginState) case newGame(NewGameState) public
init() { self = .login(.init()) } } public struct AppState: Equatable { public var login: LoginState? = LoginState() public var newGame: NewGameState? public init() {} } public var body: some View { SwitchStore(self.store) { CaseLet( state: /AppState.login, action: AppAction.login ) { store in NavigationView { LoginView(store: store) } .navigationViewStyle(StackNavigationViewStyle()) } CaseLet( state: /AppState.newGame, action: AppAction.newGame ) { store in NavigationView { NewGameView(store: store) } .navigationViewStyle(StackNavigationViewStyle()) } } @ViewBuilder public var body: some View { IfLetStore( self.store.scope(state: \.login, action: AppAction.login) ) { store in NavigationView { LoginView(store: store) } .navigationViewStyle(StackNavigationViewStyle()) } IfLetStore( self.store.scope(state: \.newGame, action: AppAction.newGame) ) { store in NavigationView { NewGameView(store: store) } .navigationViewStyle(StackNavigationViewStyle()) } } ҎલͷΓํ 4XJUDI4UPSF$BTF-FUͰͷΓํ 4XJGU6*7JFX 4XJGU6*7JFX 4UBUF 4UBUF -
public var body: some View { SwitchStore(self.store) { CaseLet( state:
/AppState.login, action: AppAction.login ) { store in NavigationView { LoginView(store: store) } .navigationViewStyle(StackNavigationViewStyle()) } CaseLet( state: /AppState.newGame, action: AppAction.newGame ) { store in NavigationView { NewGameView(store: store) } .navigationViewStyle(StackNavigationViewStyle()) } Default { Text(“ະ࣮: ͋ͱͰ͍͍ײ͡ʹCaseLetॻ͘”) } } 4XJGU6*7JFX DefaultΛͬͯΈΔྫ %FGBVMU։ൃ࣌͘Β͍ʹͬͯجຊతʹ$BTF-FUͰཏ͠Α͏ public enum AppState: Equatable { case login(LoginState) case newGame(NewGameState) case foo(FooState) public init() { self = .login(.init()) } } 4UBUF -
લఏ ϩάΠϯը໘ ϩάΠϯࡁΈͳΒ දࣔ͠ͳ͍ -PHJO 7JFX /FX (BNF 7JFX ϩάΠϯఆ
ͯ͠ ϩάΠϯͯͨ͠Β NewGameView ىಈ -
-PHJO 7JFX /FX (BNF 7JFX ىಈ public enum AppState: Equatable
{ case launch(LaunchState) case login(LoginState) case newGame(NewGameState) public init() { self = .launch(.init()) } } -BVODI 7JFX ϩάΠϯ ͯ͠ͳ͚Ε LoginView ϩάΠϯͯ͠Ε NewGameView Ԡ༻ྫ1 LaunchViewͰΞχϝʔγϣϯͱ͔Ͱ͖Δ -
ىಈ public struct AppState: Equatable { enum Scene: Equatable {
case login(LoginState) case newGame(NewGameState) } var scene: Scene var flag: Bool // ڞ௨ͳԿ͔ public init( scene: Scene = .loginCore(.init()) flag: Bool = false ) { self.scene = scene self.flag = flag } } 4UBUF -PHJO 7JFX /FX (BNF 7JFX ϩάΠϯఆ ͯ͠ NewGameView Ԡ༻ྫ2 ॴ: CathPathͷ༷Λཧղ͠ͳ͍ͱೲಘͰ͖ͳ͍ΓํʹͳΔ -
ىಈ public struct RootState: Equatable { var appCore: AppCoreState var
flag: Bool // ڞ௨ͳԿ͔ public init( appCore: AppCoreState = .loginState(.init()) flag: Bool = false ) { self.appCore = appCore self.flag = flag } } let reducer = Reducer.combine( appCoreReducer( // … ), Reducer { // … } ) 4UBUF -PHJO 7JFX /FX (BNF 7JFX ϩάΠϯఆ ͯ͠ NewGameView Ԡ༻ྫ2.1 public enum AppCoreState: Equatable { case login(LoginState) case newGame(NewGameState) } public enum AppCoreAction: Equatable { case login(LoginAction) case newGame(NewGameAction) } $PSFͱͯ͠FOVN4UBUFʹ͢Δ͕3PPUTUSVDU