Skip to content

Commit

Permalink
Delete flatMapWorkflow.
Browse files Browse the repository at this point in the history
`WorkflowRunnerViewModel` now uses `WorkflowHost` directly.
  • Loading branch information
zach-klippenstein committed May 30, 2019
1 parent ae0de55 commit fb1a6d9
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 209 deletions.
1 change: 0 additions & 1 deletion kotlin/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ include ':samples:tictactoe:common'
include ':workflow-core'
include ':workflow-runtime'
include ':workflow-rx2'
include ':workflow-rx2-runtime'
include ':workflow-testing'
include ':workflow-ui-core'
include ':workflow-ui-android'
3 changes: 0 additions & 3 deletions kotlin/workflow-rx2-runtime/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions kotlin/workflow-rx2-runtime/gradle.properties

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion kotlin/workflow-ui-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
api deps.rxjava2.rxjava2
api deps.transition

implementation project(':workflow-rx2-runtime')
implementation project(':workflow-runtime')
implementation deps.appcompatv7
implementation deps.kotlin.coroutines.android
implementation deps.kotlin.coroutines.core
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
/*
* Copyright 2019 Square Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'com.vanniktech.maven.publish'
apply plugin: 'org.jetbrains.dokka'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dokka rootProject.ext.defaultDokkaConfig
package com.squareup.workflow.ui

dependencies {
compileOnly deps.annotations.intellij
import io.reactivex.Flowable
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.reactive.openSubscription

api project(':workflow-runtime')
api deps.kotlin.stdLib.jdk6
api deps.kotlin.coroutines.core
api deps.rxjava2.rxjava2

implementation deps.kotlin.coroutines.rx2

testImplementation project(':workflow-testing')
testImplementation deps.kotlin.test.jdk
/**
* TODO kdoc
*
* TODO unit tests
*/
@FlowPreview
@UseExperimental(ObsoleteCoroutinesApi::class)
@Suppress("NOTHING_TO_INLINE")
internal inline fun <T> Flowable<out T>.asFlow(): Flow<T> = flow {
openSubscription().consumeEach {
emit(it)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import com.squareup.workflow.Workflow
import io.reactivex.BackpressureStrategy.LATEST
import io.reactivex.Flowable
import io.reactivex.Observable
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf

/**
* Uses a [Workflow] and a [ViewRegistry] to drive a [WorkflowLayout].
Expand All @@ -43,7 +46,7 @@ interface WorkflowRunner<out OutputT> {
* A stream of the [output][OutputT] values emitted by the running
* [Workflow][com.squareup.workflow.Workflow].
*/
val output: Observable<out OutputT>
val output: Flowable<out OutputT>

val renderings: Observable<out Any>

Expand All @@ -57,11 +60,12 @@ interface WorkflowRunner<out OutputT> {
* It's probably more convenient to use [FragmentActivity.setContentWorkflow]
* rather than calling this method directly.
*/
@FlowPreview
fun <InputT, OutputT : Any> of(
activity: FragmentActivity,
viewRegistry: ViewRegistry,
workflow: Workflow<InputT, OutputT, Any>,
inputs: Flowable<InputT>,
inputs: Flow<InputT>,
savedInstanceState: Bundle?
): WorkflowRunner<OutputT> {
val factory =
Expand All @@ -71,6 +75,24 @@ interface WorkflowRunner<out OutputT> {
as WorkflowRunner<OutputT>
}

/**
* Returns a [ViewModel][android.arch.lifecycle.ViewModel] implementation of
* [WorkflowRunner], tied to the given [activity].
*
* It's probably more convenient to use [FragmentActivity.setContentWorkflow]
* rather than calling this method directly.
*/
@UseExperimental(FlowPreview::class)
fun <InputT, OutputT : Any> of(
activity: FragmentActivity,
viewRegistry: ViewRegistry,
workflow: Workflow<InputT, OutputT, Any>,
inputs: Flowable<InputT>,
savedInstanceState: Bundle?
): WorkflowRunner<OutputT> {
return of(activity, viewRegistry, workflow, inputs.asFlow(), savedInstanceState)
}

/**
* Convenience overload for workflows unconcerned with back-pressure of their inputs.
*/
Expand All @@ -87,14 +109,15 @@ interface WorkflowRunner<out OutputT> {
/**
* Convenience overload for workflows that take one input value rather than a stream.
*/
@UseExperimental(FlowPreview::class)
fun <InputT, OutputT : Any> of(
activity: FragmentActivity,
viewRegistry: ViewRegistry,
workflow: Workflow<InputT, OutputT, Any>,
input: InputT,
savedInstanceState: Bundle?
): WorkflowRunner<OutputT> {
return of(activity, viewRegistry, workflow, Observable.just(input), savedInstanceState)
return of(activity, viewRegistry, workflow, flowOf(input), savedInstanceState)
}

/**
Expand All @@ -116,11 +139,12 @@ interface WorkflowRunner<out OutputT> {
* It's probably more convenient to subclass [WorkflowFragment] rather than calling
* this method directly.
*/
@FlowPreview
fun <InputT, OutputT : Any> of(
fragment: Fragment,
viewRegistry: ViewRegistry,
workflow: Workflow<InputT, OutputT, Any>,
inputs: Flowable<InputT>,
inputs: Flow<InputT>,
savedInstanceState: Bundle?
): WorkflowRunner<OutputT> {
val factory =
Expand All @@ -130,6 +154,24 @@ interface WorkflowRunner<out OutputT> {
as WorkflowRunner<OutputT>
}

/**
* Returns a [ViewModel][android.arch.lifecycle.ViewModel] implementation of
* [WorkflowRunner], tied to the given [fragment].
*
* It's probably more convenient to subclass [WorkflowFragment] rather than calling
* this method directly.
*/
@UseExperimental(FlowPreview::class)
fun <InputT, OutputT : Any> of(
fragment: Fragment,
viewRegistry: ViewRegistry,
workflow: Workflow<InputT, OutputT, Any>,
inputs: Flowable<InputT>,
savedInstanceState: Bundle?
): WorkflowRunner<OutputT> {
return of(fragment, viewRegistry, workflow, inputs.asFlow(), savedInstanceState)
}

/**
* Convenience overload for workflows unconcerned with back-pressure of their inputs.
*/
Expand All @@ -146,14 +188,15 @@ interface WorkflowRunner<out OutputT> {
/**
* Convenience overload for workflows that take one input value rather than a stream.
*/
@UseExperimental(FlowPreview::class)
fun <InputT, OutputT : Any> of(
fragment: Fragment,
viewRegistry: ViewRegistry,
workflow: Workflow<InputT, OutputT, Any>,
input: InputT,
savedInstanceState: Bundle?
): WorkflowRunner<OutputT> {
return of(fragment, viewRegistry, workflow, Flowable.just(input), savedInstanceState)
return of(fragment, viewRegistry, workflow, flowOf(input), savedInstanceState)
}

/**
Expand Down
Loading

0 comments on commit fb1a6d9

Please sign in to comment.