@@ -11,28 +11,42 @@ func stateMachine(initial: State) -> StateMachine<State, Event, Output> {
1111 StateMachine ( initial: . idle) {
1212 When ( states: OneOf {
1313 State . idle
14- State . loaded ( query : entries : )
14+ State . loaded ( context : )
1515 State . failed
1616 } ) { _ in
1717 Execute . noOutput
1818 } transitions: { _ in
1919 On ( event: Event . searchIsRequested ( query: ) ) { query in
2020 Guard ( predicate: !query. isEmpty)
2121 } transition: { query in
22- Transition ( to: State . searching ( query: query) )
22+ Transition ( to: State . searching ( context : State . Context ( query: query) ) )
2323 }
2424 }
2525
26- When ( state: State . searching ( query : ) ) { query in
27- Execute ( output: Output . search ( query: query) )
28- } transitions: { query in
26+ When ( state: State . searching ( context : ) ) { context in
27+ Execute ( output: Output . search ( query: context . query) )
28+ } transitions: { context in
2929 On ( event: Event . searchHasSucceeded ( entries: ) ) { entries in
30- Transition ( to: State . loaded ( query: query, entries: entries) )
30+ Transition ( to: State . loaded ( context : State . Context ( query: context . query, entries: entries) ) )
3131 }
3232
3333 On ( event: Event . searchHasFailed) { _ in
3434 Transition ( to: State . failed)
3535 }
36+
37+ On ( event: Event . searchIsRequested ( query: ) ) { query in
38+ Guard ( predicate: !query. isEmpty)
39+ } transition: { query in
40+ Transition ( to: State . searching ( context: State . Context ( query: query, entries: context. entries) ) )
41+ }
42+ }
43+
44+ When ( state: State . loaded ( context: ) ) { _ in
45+ Execute . noOutput
46+ } transitions: { context in
47+ On ( event: Event . refreshIsRequested) { _ in
48+ Transition ( to: State . searching ( context: context) )
49+ }
3650 }
3751 }
3852}
0 commit comments