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

Open up the component's internal methods for testing #28

Merged
merged 1 commit into from
Aug 22, 2023
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
45 changes: 32 additions & 13 deletions strada/src/main/kotlin/dev/hotwire/strada/BridgeComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ abstract class BridgeComponent<in D : BridgeDestination>(
) {
private val receivedMessages = hashMapOf<String, Message>()

internal fun didReceive(message: Message) {
receivedMessages[message.event] = message
onReceive(message)
}

internal fun didStart() {
onStart()
}

internal fun didStop() {
onStop()
}

/**
* Returns the last received message for a given `event`, if available.
*/
Expand All @@ -32,6 +19,38 @@ abstract class BridgeComponent<in D : BridgeDestination>(
*/
abstract fun onReceive(message: Message)

/**
* This passes a received message to onReceive(message), caching it
* for use with replyTo(event) and receivedMessageFor(event).
*
* NOTE: This should not be called directly from within a component,
* but is available to use for testing.
*/
fun didReceive(message: Message) {
receivedMessages[message.event] = message
onReceive(message)
}

/**
* This passes the start lifecycle event to onStart().
*
* NOTE: This should not be called directly from within a component,
* but is available to use for testing.
*/
fun didStart() {
onStart()
}

/**
* This passes the stop lifecycle event to onStop().
*
* NOTE: This should not be called directly from within a component,
* but is available to use for testing.
*/
fun didStop() {
onStop()
}

/**
* Called when the component's destination starts (and is active)
* based on its lifecycle events. You can use this as an opportunity
Expand Down
Loading