-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* automatic function serialization * lint * flowInstance transition * more lint * get doesn't work * nodeserializablefunction update * flowController transition * constants controller function cache * lint and change test equals back * expression eval and beacon * logger and playerFlowState * the rest of the getInvokables
- Loading branch information
1 parent
e9fa10d
commit 4f29d3b
Showing
16 changed files
with
181 additions
and
37 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...lin/com/intuit/playerui/core/bridge/serialization/serializers/NodeSerializableFunction.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,84 @@ | ||
package com.intuit.playerui.core.bridge.serialization.serializers | ||
|
||
import com.intuit.playerui.core.bridge.Invokable | ||
import com.intuit.playerui.core.bridge.Node | ||
import com.intuit.playerui.core.bridge.NodeWrapper | ||
import com.intuit.playerui.core.bridge.getInvokable | ||
import com.intuit.playerui.core.bridge.serialization.format.serializer | ||
import com.intuit.playerui.core.experimental.ExperimentalPlayerApi | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlin.reflect.KProperty | ||
|
||
/** Delegate for automatic deserialization of [Node] values */ | ||
internal class NodeSerializableFunction<R> private constructor( | ||
private val provider: () -> Node, | ||
private val serializer: DeserializationStrategy<R>, | ||
internal val strategy: CacheStrategy, | ||
private val name: String?, | ||
) { | ||
|
||
/** Caching strategy for determining how to pull the value from [Node] on subsequent attempts */ | ||
public enum class CacheStrategy { | ||
None, | ||
Full, | ||
} | ||
|
||
/** Cache of container [Node] that will reset the [value] cache if out-of-date with the [provider] */ | ||
private var cache: Node = provider(); get() { | ||
val provided = provider() | ||
field = provided | ||
value = null | ||
|
||
return field | ||
} | ||
|
||
/** Cache of the [T] value, along with the backing [Node] for objects */ | ||
private var value: Invokable<R>? = null | ||
|
||
public operator fun getValue(thisRef: Any?, property: KProperty<*>): Invokable<R> { | ||
// early exit if we have a value and explicitly using the cache | ||
value?.takeIf { strategy == CacheStrategy.Full }?.let { | ||
return it | ||
} | ||
|
||
val key = name ?: property.name | ||
|
||
// will reset cache and value if mismatch | ||
val node = cache | ||
|
||
// else get and deserialize the value | ||
return node.getInvokable(key, serializer)!! | ||
} | ||
|
||
public companion object { | ||
|
||
/** Smart constructor responsible for determining the correct [CacheStrategy] and [defaultValue] from the [serializer], if either are not provided */ | ||
@ExperimentalPlayerApi | ||
public operator fun <R> invoke( | ||
provider: () -> Node, | ||
serializer: DeserializationStrategy<R>, | ||
strategy: CacheStrategy? = null, | ||
name: String? = null, | ||
): NodeSerializableFunction<R> = NodeSerializableFunction( | ||
provider, | ||
serializer, | ||
strategy ?: CacheStrategy.Full, | ||
name, | ||
) | ||
} | ||
} | ||
|
||
@ExperimentalPlayerApi | ||
internal fun <R> NodeWrapper.NodeSerializableFunction( | ||
serializer: DeserializationStrategy<R>, | ||
strategy: NodeSerializableFunction.CacheStrategy? = null, | ||
name: String? = null, | ||
defaultValue: (Node.(String) -> Invokable<R>)? = null, | ||
): NodeSerializableFunction<R> = NodeSerializableFunction(::node, serializer, strategy, name) | ||
|
||
@ExperimentalPlayerApi | ||
internal inline fun <reified R> NodeWrapper.NodeSerializableFunction( | ||
strategy: NodeSerializableFunction.CacheStrategy? = null, | ||
name: String? = null, | ||
noinline defaultValue: (Node.(String) -> Invokable<R>)? = null, | ||
): NodeSerializableFunction<R> = NodeSerializableFunction(node.format.serializer<R>(), strategy, name, defaultValue) |
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
11 changes: 9 additions & 2 deletions
11
jvm/core/src/main/kotlin/com/intuit/playerui/core/data/DataController.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
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
8 changes: 6 additions & 2 deletions
8
jvm/core/src/main/kotlin/com/intuit/playerui/core/flow/FlowController.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
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
Oops, something went wrong.