-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reducer, sideEffectHandler를 생성자에서 추상 프로퍼티로 변경
- Loading branch information
1 parent
26ebac3
commit f47379e
Showing
6 changed files
with
81 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 10 additions & 4 deletions
14
example/android/src/main/java/dohun/kim/kinda/example_android/count/CountViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package dohun.kim.kinda.example_android.count | ||
|
||
import dohun.kim.kinda.kinda_android.KindaViewModel | ||
import dohun.kim.kinda.kinda_core.KindaReducer | ||
import dohun.kim.kinda.kinda_core.KindaSideEffectHandler | ||
|
||
class CountViewModel : KindaViewModel<CountState, CountEvent, CountSideEffect>( | ||
initialState = CountState(), | ||
reducer = CountReducer(), | ||
sideEffectHandler = CountSideEffectHandler() | ||
) | ||
initialState = CountState() | ||
) { | ||
override val reducer: KindaReducer<CountState, CountEvent, CountSideEffect> | ||
get() = CountReducer() | ||
|
||
override val sideEffectHandler: KindaSideEffectHandler<CountState, CountEvent, CountSideEffect> | ||
get() = CountSideEffectHandler() | ||
} |
10 changes: 7 additions & 3 deletions
10
example/android/src/main/java/dohun/kim/kinda/example_android/login/LoginViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package dohun.kim.kinda.example_android.login | ||
|
||
import dohun.kim.kinda.kinda_android.KindaViewModel | ||
import dohun.kim.kinda.kinda_core.KindaReducer | ||
import dohun.kim.kinda.kinda_core.KindaSideEffectHandler | ||
|
||
class LoginViewModel : KindaViewModel<LoginState, LoginEvent, LoginSideEffect>( | ||
initialState = LoginState(), | ||
reducer = LoginReducer(), | ||
sideEffectHandler = LoginSideEffectHandler() | ||
initialState = LoginState() | ||
) { | ||
override val reducer: KindaReducer<LoginState, LoginEvent, LoginSideEffect> | ||
get() = LoginReducer() | ||
override val sideEffectHandler: KindaSideEffectHandler<LoginState, LoginEvent, LoginSideEffect> | ||
get() = LoginSideEffectHandler() | ||
} |
49 changes: 28 additions & 21 deletions
49
example/androidwithdsl/src/main/java/dohun/kim/kinda/androidwithdsl/CountViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,40 @@ | ||
package dohun.kim.kinda.androidwithdsl | ||
|
||
import dohun.kim.kinda.kinda_android.KindaViewModel | ||
import dohun.kim.kinda.kinda_core.KindaReducer | ||
import dohun.kim.kinda.kinda_core.KindaSideEffectHandler | ||
import dohun.kim.kinda.kinda_dsl.buildReducer | ||
import dohun.kim.kinda.kinda_dsl.buildSideEffectHandler | ||
import kotlinx.coroutines.delay | ||
|
||
class CountViewModel : KindaViewModel<CountState, CountEvent, CountSideEffect>( | ||
initialState = CountState(), | ||
reducer = buildReducer { | ||
whenEvent<CountEvent.AttemptMagic> { | ||
dispatch(CountSideEffect.Magic) | ||
} | ||
initialState = CountState() | ||
) { | ||
|
||
whenEvent<CountEvent.Decrease> { | ||
next(copy(count = count - 1)) | ||
} | ||
override val reducer: KindaReducer<CountState, CountEvent, CountSideEffect> | ||
get() = buildReducer { | ||
whenEvent<CountEvent.AttemptMagic> { | ||
dispatch(CountSideEffect.Magic) | ||
} | ||
|
||
whenEvent<CountEvent.Increase> { | ||
next(copy(count = count + 1)) | ||
} | ||
whenEvent<CountEvent.Decrease> { | ||
next(copy(count = count - 1)) | ||
} | ||
|
||
whenEvent<CountEvent.Increase1000> { | ||
next(copy(count = count + 1000)) | ||
} | ||
}, | ||
sideEffectHandler = buildSideEffectHandler { | ||
whenSideEffect<CountSideEffect.Magic> { | ||
delay(1000) | ||
CountEvent.Increase1000 | ||
whenEvent<CountEvent.Increase> { | ||
next(copy(count = count + 1)) | ||
} | ||
|
||
whenEvent<CountEvent.Increase1000> { | ||
next(copy(count = count + 1000)) | ||
} | ||
} | ||
} | ||
) | ||
|
||
override val sideEffectHandler: KindaSideEffectHandler<CountState, CountEvent, CountSideEffect> | ||
get() = buildSideEffectHandler { | ||
whenSideEffect<CountSideEffect.Magic> { | ||
delay(1000) | ||
CountEvent.Increase1000 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters