diff --git a/formula/src/main/java/com/instacart/formula/FormulaContext.kt b/formula/src/main/java/com/instacart/formula/FormulaContext.kt index 6924da5d..807afc78 100644 --- a/formula/src/main/java/com/instacart/formula/FormulaContext.kt +++ b/formula/src/main/java/com/instacart/formula/FormulaContext.kt @@ -14,51 +14,14 @@ abstract class FormulaContext 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 onEvent( - transition: Transition, - ): Listener { - 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 onEvent( - key: Any, - transition: Transition, - ): Listener { - 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): () -> 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, ): () -> Unit { val listener = onEvent(key, transition) @@ -66,28 +29,20 @@ abstract class FormulaContext internal constructor( } /** - * 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 eventCallback( - transition: Transition, - ): Listener { - 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 eventCallback( - key: Any, + fun onEvent( + key: Any? = null, transition: Transition, ): Listener { - return onEvent(key, transition) + return eventListener( + key = createScopedKey(transition.type(), key), + transition = transition + ) } /**