Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Renames ComposeViewFactoryRoot to CompositionRoot and decouples the implementation. #34

Merged
merged 1 commit into from
May 28, 2020

Conversation

zach-klippenstein
Copy link
Collaborator

The root is now applied via a ViewRegistry wrapper that wraps individual factories
to apply the root, instead of having this logic hard-coded inside ComposeViewFactory.

This approach is more flexible in general (could be used to do other tricks), and decouples
the rooting feature from the rest of the code.

@zach-klippenstein zach-klippenstein requested a review from rjrjr May 19, 2020 23:37
Comment on lines +49 to +42
internal fun ViewRegistry.mapFactories(
transform: (ViewFactory<*>) -> ViewFactory<*>
): ViewRegistry = object : ViewRegistry {
override val keys: Set<KClass<*>> get() = [email protected]

override fun <RenderingT : Any> getFactoryFor(
renderingType: KClass<out RenderingT>
): ViewFactory<RenderingT> {
val transformedFactory = transform([email protected](renderingType))
check(transformedFactory.type == renderingType) {
"Expected transform to return a ViewFactory that is compatible with $renderingType, " +
"but got one with type ${transformedFactory.type}"
}
@Suppress("UNCHECKED_CAST")
return transformedFactory as ViewFactory<RenderingT>
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the key to the decoupled implementation. This technique can be used to do other stuff too, like e.g. apply a modifier to each ViewFactory's view.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I've already had a few use cases for this, should we move it to the main repo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure!

@zach-klippenstein zach-klippenstein force-pushed the zachklipp/even-better-root branch from f94ee4c to 497a7e3 Compare May 19, 2020 23:52
@zach-klippenstein
Copy link
Collaborator Author

Failed test looks like a weird github issue – same shard appears twice, passed the second time.

…mplementation.

The root is now applied via a `ViewRegistry` wrapper that wraps individual factories
to apply the root, instead of having this logic hard-coded inside `ComposeViewFactory`.

This approach is more flexible in general (could be used to do other tricks), and decouples
the rooting feature from the rest of the code.
@zach-klippenstein zach-klippenstein force-pushed the zachklipp/even-better-root branch from 497a7e3 to ea57ae0 Compare May 28, 2020 22:29
@zach-klippenstein zach-klippenstein merged commit 508029e into master May 28, 2020
@zach-klippenstein zach-klippenstein deleted the zachklipp/even-better-root branch May 28, 2020 22:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants