Skip to content

Instantly share code, notes, and snippets.

View rjrjr's full-sized avatar

Ray Ryan rjrjr

View GitHub Profile
package com.squareup.sample.compose.hellocomposebinding
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.Rendering
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.HG
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.HG.Goodbye
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.HG.Hello
import com.squareup.sample.compose.hellocomposebinding.HelloWorkflow.State
import com.squareup.sample.compose.hellocomposeworkflow.HelloWorkflow
import com.squareup.workflow1.Snapshot
import com.squareup.workflow1.StatefulWorkflow
package com.squareup.workflow.pos.text
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import android.widget.TextView
import com.squareup.util.coroutines.launchWhenAttached
import com.squareup.workflow1.ExperimentalWorkflowApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
class HelloWorkflowActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// This ViewModel will survive configuration changes. It's instantiated
// by the first call to viewModels(), and that original instance is returned by
// succeeding calls.
val model: HelloViewModel by viewModels()
rjrjr / Gatekeeper.kt
Last active August 5, 2021 21:30
Gatekeeper workflow pattern
* In our production code, this typealias is more interesting,
* something like AlertContainerScreen<PanelContainerScreen<R>>
typealias MetaRootRendering<R>: AlertContainerScreen<R>
data class ActivityAndRoot<R> (
val activity: Activity,
val root: R
rjrjr / java-sealed-class
Last active March 4, 2023 22:10
Poor Man's Sealed Classes (visitor pattern)
* For Java developers all excited by and jealous of Kotlin's sealed classes.
* Do this when you wish you could put parameters on an enum.
public class PoorMan {
interface Event {
<T> T dispatch(EventHandler<T> handler);
interface EventHandler<T> {
package mortar;
import android.view.View;
import mortar.bundler.BundleService;
public class NewViewPresenter<V extends View> extends NewPresenter<V> {
@Override protected final MortarScope extractScope(V view) {
return MortarScope.getScope(view.getContext());
package mortar;
public abstract class NewPresenter<V> {
private V view = null;
private Scoped registration = new Scoped() {
@Override public void onEnterScope(MortarScope scope) {