title: Access business logic layer directly from a "small" composable
body: <p>I moved my navigation logic to view models to decouple it from <em>Navigation Component</em>, like <a href="https://joebirch.co/android/modular-navigation-with-jetpack-compose/" rel="nofollow noreferrer">here</a>.</p>
  <p>As it is typical for <code>Composable</code> to have <a href="https://developer.android.com/jetpack/compose/state#viewmodels-source-of-truth" rel="nofollow noreferrer">screen-level view model</a>, it would mean, that child <code>Composable</code>s of that screen-level <code>Composable</code> should pass some events to the parent, screen-level <code>Composable</code> (via callbacks) that will pass the event in the end to the view model.</p>
  <p>This however would require passing the events all the way round through all <code>Composable</code>s between composable that caused event to the parent, screen-level <code>Composable</code>.</p>
  <p>I would say it's fine <strong>in most</strong> of the cases.</p>
  <p>However, one example which is not fine, is <strong>a small (not-screen level) UI element</strong> which has <strong>business logic tied to it</strong>. And that business logic is a <a href="https://en.wikipedia.org/wiki/Cross-cutting_concern" rel="nofollow noreferrer">cross cutting concern</a> for the app.</p>
  <p>Imagine writing Facebook-like app in Compose. In a variety of different screens you can see users' thumbnails (friends list, members of a group, authors of posts etc.)</p>
  <p>And every time you click on a thumbnail, a pice of business logic is executed, which ends up in navigatig you to thumbnail owner's profile.
  It's clearly a cross cutting concern and implementing it in a view model for each screen and passing the events up to the screen-level <code>Composable</code> seem to cause unncecessary overhead.</p>
  <p><strong>How to handle such &quot;small&quot; (not-screen level) <code>Composable</code>s that require access to business logic?</strong></p>
  <p>Using view model for such a small composable may be an option, but feels a little bit strange, as the view models seem to be a default choice for <em>screen-level</em> composables.</p>
  <p>It may be also possible to achieve it with <code>CompositionLocal</code>s, but it seems to be <a href="https://developer.android.com/jetpack/compose/compositionlocal#deciding" rel="nofollow noreferrer">excatly the discouraged case.</a></p>