Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax ChildAware API requirements #336

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## Pending changes

- [#336](https://github.com/bumble-tech/appyx/pulls/336) – **Updated**: ChildAware API does not enforce Node subtypes only anymore, making it possible to use interfaces as public contracts for child nodes.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.NodeAware
import kotlin.reflect.KClass

interface ChildAware<N: Node> : NodeAware<N> {
interface ChildAware<N : Node> : NodeAware<N> {

fun <T : Node> whenChildAttached(
fun <T : Any> whenChildAttached(
child: KClass<T>,
callback: ChildCallback<T>,
)

fun <T1 : Node, T2 : Node> whenChildrenAttached(
fun <T1 : Any, T2 : Any> whenChildrenAttached(
child1: KClass<T1>,
child2: KClass<T2>,
callback: ChildrenCallback<T1, T2>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal sealed class ChildAwareCallbackInfo {

abstract fun onRegistered(activeNodes: List<Node>)

class Single<T : Node>(
class Single<T : Any>(
private val child: KClass<T>,
private val callback: ChildCallback<T>,
private val parentLifecycle: Lifecycle,
Expand All @@ -39,7 +39,7 @@ internal sealed class ChildAwareCallbackInfo {

}

class Double<T1 : Node, T2 : Node>(
class Double<T1 : Any, T2 : Any>(
private val child1: KClass<T1>,
private val child2: KClass<T2>,
private val callback: ChildrenCallback<T1, T2>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ChildAwareImpl<N : Node> : ChildAware<N> {
}
}

override fun <T : Node> whenChildAttached(
override fun <T : Any> whenChildAttached(
child: KClass<T>,
callback: ChildCallback<T>
) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check if child is a Node to fail early? Rather that never get a callback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is not, that the main point. In my sample Child is just an interface, like we have in our templates.

Expand All @@ -64,7 +64,7 @@ class ChildAwareImpl<N : Node> : ChildAware<N> {
lifecycle.removeWhenDestroyed(info)
}

override fun <T1 : Node, T2 : Node> whenChildrenAttached(
override fun <T1 : Any, T2 : Any> whenChildrenAttached(
child1: KClass<T1>,
child2: KClass<T2>,
callback: ChildrenCallback<T1, T2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,25 +241,25 @@ abstract class ParentNode<NavTarget : Any>(

// region ChildAware

protected fun <T : Node> whenChildAttached(child: KClass<T>, callback: ChildCallback<T>) {
protected fun <T : Any> whenChildAttached(child: KClass<T>, callback: ChildCallback<T>) {
childAware.whenChildAttached(child, callback)
}

protected fun <T1 : Node, T2 : Node> whenChildrenAttached(
protected fun <T1 : Any, T2 : Any> whenChildrenAttached(
child1: KClass<T1>,
child2: KClass<T2>,
callback: ChildrenCallback<T1, T2>
) {
childAware.whenChildrenAttached(child1, child2, callback)
}

protected inline fun <reified T : Node> whenChildAttached(
protected inline fun <reified T : Any> whenChildAttached(
noinline callback: ChildCallback<T>,
) {
whenChildAttached(T::class, callback)
}

protected inline fun <reified T1 : Node, reified T2 : Node> whenChildrenAttached(
protected inline fun <reified T1 : Any, reified T2 : Any> whenChildrenAttached(
noinline callback: ChildrenCallback<T1, T2>,
) {
whenChildrenAttached(T1::class, T2::class, callback)
Expand Down