-
Notifications
You must be signed in to change notification settings - Fork 13
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
Rename Stream to Action. #229
Conversation
formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxDisposableAction.kt
Outdated
Show resolved
Hide resolved
package com.instacart.formula | ||
|
||
/** | ||
* An action returned by [evaluation][Formula.evaluate] that will run for any new unique |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more elaborated documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 on being explicit on what the contract is here in regard to e.g. key
* | ||
* Use this stream to send a effects with latest [Data] value. | ||
* ``` | ||
* events(Stream.onData(itemId)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: need to audit this and rename it.
@@ -121,7 +121,7 @@ abstract class FormulaContext<State> internal constructor( | |||
class UpdateBuilder<State>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: I'd like to move this out of into an ActionBuilder
*/ | ||
data class Evaluation<out Output>( | ||
val output: Output, | ||
val updates: List<Update<*>> = emptyList() | ||
) | ||
val actions: List<BoundAction<*>> = emptyList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To have better naming downstream, it might be worth wrapping this into a data class?
data class Actions(val list: List<ICBoundAction<*>>)
@@ -99,7 +99,7 @@ abstract class FormulaContext<State> internal constructor( | |||
/** | |||
* Provides an [UpdateBuilder] that enables [Formula] to declare various events and effects. | |||
*/ | |||
abstract fun updates(init: UpdateBuilder<State>.() -> Unit): List<Update<*>> | |||
abstract fun updates(init: UpdateBuilder<State>.() -> Unit): List<BoundAction<*>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: add actions
method.
@@ -170,7 +170,7 @@ abstract class FormulaContext<State> internal constructor( | |||
this@UpdateBuilder.events(stream, transition) | |||
} | |||
|
|||
@PublishedApi internal fun add(connection: Update<*>) { | |||
@PublishedApi internal fun add(connection: BoundAction<*>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: renamed connection
to action
.
*/ | ||
fun key(): Any? | ||
} | ||
typealias Stream<Message> = DisposableAction<Message> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: add @Deprecated
JaCoCo Code Coverage 80.64% ✅
Generated by 🚫 Danger |
*/ | ||
typealias Effects = () -> Unit | ||
typealias Action = () -> Unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, a good name could be DeferredAction
.
|
||
/** | ||
* Handles [Update] changes. | ||
* Handles [BoundAction] changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: rename this class to ActionManager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few nits on doc syntax
formula/src/main/java/com/instacart/formula/DisposableAction.kt
Outdated
Show resolved
Hide resolved
formula/src/main/java/com/instacart/formula/DisposableAction.kt
Outdated
Show resolved
Hide resolved
formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxDisposableAction.kt
Outdated
Show resolved
Hide resolved
e92b245
to
bec80b6
Compare
d678ab2
to
1f741ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commenting so it disappears from my github PR list, happy to review it when it is updated
package com.instacart.formula | ||
|
||
/** | ||
* An action returned by [evaluation][Formula.evaluate] that will run for any new unique |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 on being explicit on what the contract is here in regard to e.g. key
1f741ca
to
ffd7db3
Compare
ffd7db3
to
1fda990
Compare
922dd0b
to
8d9b7d6
Compare
val fetchUserStream = RxStream.fromObservable { repository.fetchUser() } | ||
fetchUserStream.onEvent { userResult -> | ||
// Do something | ||
val fetchUserAction = RxAction.fromObservable { repository.fetchUser() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads better to me than fetchUserStream
8d9b7d6
to
4fed82d
Compare
* Adapter which maps RxJava types to [Action] type. Take a look | ||
* at [RxAction.fromObservable]. | ||
*/ | ||
interface RxAction<Event> : Action<Event> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy pasted from RxStream
with documentation changes.
* | ||
* @param Event A type of event used to notify [Formula]. | ||
*/ | ||
interface Action<Event> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy pasted from Stream
with big documentation changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still see Stream
in the docs below. Intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, updated
* until [action][action] produces a value. It will recreate and resubscribe to | ||
* the [Action] whenever [Input] changes. | ||
*/ | ||
abstract class ActionFormula<Input : Any, Output : Any> : IFormula<Input, Output> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy pasted from StreamFormula
/** | ||
* Builds a list of deferred actions that will be executed by Formula runtime. | ||
*/ | ||
abstract fun actions(init: ActionBuilder<Input, State>.() -> Unit): List<BoundAction<*>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be buildActions
?
4fed82d
to
6e0a1f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe onEvent
could instead be onAction
with this name change? Just a thought
what we get in "onEvent" is the result of the action though, unless I am very confused about the direction of this change, that would still be an event to me (or another "not action" naming), |
docs/diffing.md
Outdated
@@ -3,5 +3,5 @@ TODO | |||
### Diffing | |||
Given that we recompute everything with each state change, there is an internal diffing mechanism with Formula. This | |||
mechanism ensures that: | |||
1. RxJava streams are only subscribed to once. | |||
1. RxJava actions are only subscribed to once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this still be streams
to keep with Rx terminology?
@Laimiux Just spitballing here but I'm wondering if
Thoughts? |
That's correct, for example
@mattkranzler5 I guess in my mind event is something that an action can produce/emit. For example, you can have an action which saves data to the backend and emits an event of success/failure status. RxAction.fromObservable { userRepo.updateEmail(state.newEmail) }.onEvent { status ->
when (status) {
SUCCESS -> transition { toastManager.showToast("Email updated!") }
ERROR -> transition { toastManager.showToast("Email failed to update") }
}
} |
@Laimiux the way I read the above is that something from an |
6e0a1f9
to
e75ba9f
Compare
I like the idea of simplifying naming but I'd worry in this case that using the same term to refer to the callback and the emission would lead to more confusion. One downside to the rename is that in my mind |
With
I do agree that Action.perform { analytics.trackPageOpened() }
Action.perform(key = data) { analytics.trackDataChanged(data) }
Action.performOnTermination() { analytics.trackPageClosed() }
Action.emit(data).onEvent {
// if you need to do a state change when data changes
transition()
} But, I think this is a bigger change that needs to be thought through more (around the API and consistency). |
12499f8
to
63a49bb
Compare
I was thinking that
The naming makes more sense to me but I'll get used to whatever we decide. |
63a49bb
to
639902c
Compare
I want to rename
Stream
toAction
updates
toactions
will keep the naming more consistentAction.onInit
and similar methods seems better named thanStream.onInit
Stream
Action
RxStream
RxAction
FlowStream
FlowAction
BoundedStream
BoundedAction
Evaluation.updates
Evaluation.actions