-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic storefront with datatable in Destkop example
- Loading branch information
1 parent
67ba908
commit 7e60570
Showing
33 changed files
with
1,017 additions
and
127 deletions.
There are no files selected for viewing
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
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
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
58 changes: 58 additions & 0 deletions
58
...ugger-client/src/commonMain/kotlin/com/copperleaf/ballast/debugger/JsonDebuggerAdapter.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,58 @@ | ||
package com.copperleaf.ballast.debugger | ||
|
||
import io.ktor.http.ContentType | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.json.Json | ||
|
||
public class JsonDebuggerAdapter<Inputs : Any, Events : Any, State : Any>( | ||
private val inputsSerializer: KSerializer<Inputs>? = null, | ||
private val eventsSerializer: KSerializer<Events>? = null, | ||
private val stateSerializer: KSerializer<State>? = null, | ||
private val json: Json = Json, | ||
) : DebuggerAdapter<Inputs, Events, State> { | ||
override fun serializeInput(input: Inputs): Pair<ContentType, String> { | ||
return if (inputsSerializer != null) { | ||
ContentType.Application.Json to json.encodeToString(inputsSerializer, input) | ||
} else { | ||
ContentType.Text.Any to input.toString() | ||
} | ||
} | ||
|
||
override fun serializeEvent(event: Events): Pair<ContentType, String> { | ||
return if (eventsSerializer != null) { | ||
ContentType.Application.Json to json.encodeToString(eventsSerializer, event) | ||
} else { | ||
ContentType.Text.Any to event.toString() | ||
} | ||
} | ||
|
||
override fun serializeState(state: State): Pair<ContentType, String> { | ||
return if (stateSerializer != null) { | ||
ContentType.Application.Json to json.encodeToString(stateSerializer, state) | ||
} else { | ||
ContentType.Text.Any to state.toString() | ||
} | ||
} | ||
|
||
override fun deserializeInput(contentType: ContentType, serializedInput: String): Inputs? { | ||
return if (inputsSerializer != null) { | ||
check(contentType == ContentType.Application.Json) | ||
json.decodeFromString(inputsSerializer, serializedInput) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun deserializeState(contentType: ContentType, serializedState: String): State? { | ||
return if (stateSerializer != null) { | ||
check(contentType == ContentType.Application.Json) | ||
json.decodeFromString(stateSerializer, serializedState) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun toString(): String { | ||
return "JsonDebuggerAdapter" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ger-client/src/commonMain/kotlin/com/copperleaf/ballast/debugger/LambdaDebuggerAdapter.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,36 @@ | ||
package com.copperleaf.ballast.debugger | ||
|
||
import io.ktor.http.ContentType | ||
|
||
internal class LambdaDebuggerAdapter<Inputs : Any, Events : Any, State : Any>( | ||
private val serializeInput: ((Inputs) -> Pair<ContentType, String>)?, | ||
private val serializeEvent: ((Events) -> Pair<ContentType, String>)?, | ||
private val serializeState: ((State) -> Pair<ContentType, String>)?, | ||
) : DebuggerAdapter<Inputs, Events, State> { | ||
override fun serializeInput(input: Inputs): Pair<ContentType, String> { | ||
return serializeInput?.invoke(input) | ||
?: (ContentType.Text.Any to input.toString()) | ||
} | ||
|
||
override fun serializeEvent(event: Events): Pair<ContentType, String> { | ||
return serializeEvent?.invoke(event) | ||
?: (ContentType.Text.Any to event.toString()) | ||
} | ||
|
||
override fun serializeState(state: State): Pair<ContentType, String> { | ||
return serializeState?.invoke(state) | ||
?: (ContentType.Text.Any to state.toString()) | ||
} | ||
|
||
override fun deserializeInput(contentType: ContentType, serializedInput: String): Inputs? { | ||
return null | ||
} | ||
|
||
override fun deserializeState(contentType: ContentType, serializedState: String): State? { | ||
return null | ||
} | ||
|
||
override fun toString(): String { | ||
return "LambdaDebuggerAdapter" | ||
} | ||
} |
Oops, something went wrong.