Skip to content
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

Remove deprecated eventCallback. #330

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 15 additions & 60 deletions formula/src/main/java/com/instacart/formula/FormulaContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,80 +14,35 @@ abstract class FormulaContext<out Input, State> internal constructor(
) {

/**
* Creates a [Listener] that takes an [Event] and performs a [Transition].
* Creates a listener that takes an event and performs a [Transition]. It uses a composite
* key of [transition] type and optional [key] property.
*
* It uses [transition] type as key.
*/
fun <Event> onEvent(
transition: Transition<Input, State, Event>,
): Listener<Event> {
return eventListener(
key = createScopedKey(transition.type()),
transition = transition
)
}

/**
* Creates a [Listener] that takes a [Event] and performs a [Transition].
*
* @param key key with which the listener is to be associated. Same key cannot be used for multiple listeners.
*/
fun <Event> onEvent(
key: Any,
transition: Transition<Input, State, Event>,
): Listener<Event> {
return eventListener(
key = createScopedKey(transition.type(), key),
transition = transition
)
}

/**
* Creates a listener that takes an event and performs a [Transition].
*
* It uses [transition] type as key.
*/
fun callback(transition: Transition<Input, State, Unit>): () -> Unit {
val listener = onEvent(transition)
return UnitListener(listener)
}

/**
* Creates a listener that takes an event and performs a [Transition].
*
* @param key key with which the listener is to be associated. Same key cannot be used for multiple listeners.
* @param key Optional key property that the listener will be associated with. Same key value
* should not be used with the same [transition] type.
*/
fun callback(
key: Any,
key: Any? = null,
transition: Transition<Input, State, Unit>,
): () -> Unit {
val listener = onEvent(key, transition)
return UnitListener(listener)
}

/**
* Creates a listener that takes a [Event] and performs a [Transition].
*
* It uses [transition] type as key.
*/
@Deprecated("Use context.onEvent {} instead.", replaceWith = ReplaceWith("onEvent(transition)"))
fun <Event> eventCallback(
transition: Transition<Input, State, Event>,
): Listener<Event> {
return onEvent(transition)
}

/**
* Creates a listener that takes a [Event] and performs a [Transition].
* Creates a [Listener] that takes a [Event] and performs a [Transition]. It uses a composite
* key of [transition] type and optional [key] property.
*
* @param key key with which the listener is to be associated. Same key cannot be used for multiple listeners.
* @param key Optional key property that the listener will be associated with. Same key value
* should not be used with the same [transition] type.
*/
@Deprecated("Use context.onEvent(key) {} instead.", replaceWith = ReplaceWith("onEvent(key, transition)"))
fun <Event> eventCallback(
key: Any,
fun <Event> onEvent(
key: Any? = null,
transition: Transition<Input, State, Event>,
): Listener<Event> {
return onEvent(key, transition)
return eventListener(
key = createScopedKey(transition.type(), key),
transition = transition
)
}

/**
Expand Down
Loading