Skip to content

Commit 77a8428

Browse files
committed
Open up the component's didReceive(), didStart(), and didStop() for use with app component testing
1 parent 427024f commit 77a8428

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

strada/src/main/kotlin/dev/hotwire/strada/BridgeComponent.kt

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ abstract class BridgeComponent<in D : BridgeDestination>(
66
) {
77
private val receivedMessages = hashMapOf<String, Message>()
88

9-
internal fun didReceive(message: Message) {
10-
receivedMessages[message.event] = message
11-
onReceive(message)
12-
}
13-
14-
internal fun didStart() {
15-
onStart()
16-
}
17-
18-
internal fun didStop() {
19-
onStop()
20-
}
21-
229
/**
2310
* Returns the last received message for a given `event`, if available.
2411
*/
@@ -32,6 +19,38 @@ abstract class BridgeComponent<in D : BridgeDestination>(
3219
*/
3320
abstract fun onReceive(message: Message)
3421

22+
/**
23+
* This passes a received message to onReceive(message), caching it
24+
* for use with replyTo(event) and receivedMessageFor(event).
25+
*
26+
* NOTE: This should not be called directly from within a component,
27+
* but is available to use for testing.
28+
*/
29+
fun didReceive(message: Message) {
30+
receivedMessages[message.event] = message
31+
onReceive(message)
32+
}
33+
34+
/**
35+
* This passes the start lifecycle event to onStart().
36+
*
37+
* NOTE: This should not be called directly from within a component,
38+
* but is available to use for testing.
39+
*/
40+
fun didStart() {
41+
onStart()
42+
}
43+
44+
/**
45+
* This passes the stop lifecycle event to onStop().
46+
*
47+
* NOTE: This should not be called directly from within a component,
48+
* but is available to use for testing.
49+
*/
50+
fun didStop() {
51+
onStop()
52+
}
53+
3554
/**
3655
* Called when the component's destination starts (and is active)
3756
* based on its lifecycle events. You can use this as an opportunity

0 commit comments

Comments
 (0)