-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
572e14a
commit afa249c
Showing
14 changed files
with
299 additions
and
245 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...imental/market/src/commonMain/kotlin/org/mobilenativefoundation/market/combineReducers.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.mobilenativefoundation.market | ||
|
||
|
||
inline fun <reified S : Market.State, reified A : Market.Action> combineReducers(vararg reducers: Market.Reducer<S, A>): Market.Reducer<S, A> { | ||
return Market.Reducer { state, action -> | ||
reducers.fold(state) { currentState, reducer -> | ||
reducer.reduce(currentState, action) | ||
} | ||
} | ||
} | ||
|
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
7 changes: 7 additions & 0 deletions
7
.../main/kotlin/org/mobilenativefoundation/sample/octonaut/android/app/market/RootReducer.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.mobilenativefoundation.sample.octonaut.android.app.market | ||
|
||
import org.mobilenativefoundation.market.Market | ||
import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction | ||
import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState | ||
|
||
typealias RootReducer = Market.Reducer<OctonautMarketState, OctonautMarketAction> |
39 changes: 39 additions & 0 deletions
39
.../mobilenativefoundation/sample/octonaut/android/app/market/reducers/CurrentUserReducer.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.mobilenativefoundation.sample.octonaut.android.app.market.reducers | ||
|
||
import org.mobilenativefoundation.market.Market | ||
import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketAction | ||
import org.mobilenativefoundation.sample.octonaut.xplat.common.market.OctonautMarketState | ||
import org.mobilenativefoundation.sample.octonaut.xplat.domain.user.api.User | ||
|
||
val currentUserReducer: Market.Reducer<OctonautMarketState, OctonautMarketAction> = | ||
Market.Reducer { state, action -> | ||
|
||
if (action is OctonautMarketAction.UpdateCurrentUser) { | ||
state.copy(currentUser = state.currentUser.copy( | ||
user = action.user?.let { | ||
User( | ||
id = it.id, | ||
email = it.email, | ||
name = it.name ?: "", | ||
login = it.login, | ||
avatarUrl = it.avatarUrl.toString(), | ||
repositories = it.repositories.nodes?.mapNotNull { repo -> repo?.id } ?: emptyList(), | ||
starredRepositories = it.starredRepositories.nodes?.mapNotNull { repo -> repo?.id } | ||
?: emptyList(), | ||
organizations = it.organizations.nodes?.mapNotNull { org -> org?.id } ?: emptyList(), | ||
pinnedItems = it.pinnedItems.let { pinnedItems -> List(pinnedItems.totalCount) { "" } }, | ||
socialAccounts = it.socialAccounts.nodes?.mapNotNull { socialAccount -> | ||
socialAccount?.let { | ||
User.SocialAccount( | ||
socialAccount.displayName, | ||
socialAccount.provider.name | ||
) | ||
} | ||
} ?: emptyList() | ||
) | ||
} | ||
)) | ||
} else { | ||
state | ||
} | ||
} |
Oops, something went wrong.