@@ -51,6 +51,11 @@ public struct StateMachineSchema<A, B, C>: StateMachineSchemaType {
5151/// `StateMachineSchemaType` documentation for more information about schemas
5252/// and subjects.
5353///
54+ /// References to class-based subjects are weak. This helps to remove
55+ /// subject-machine reference cycles, but it also means you have to keep a
56+ /// strong reference to a subject somewhere else. When subject references
57+ /// become `nil`, transitions are no longer performed.
58+ ///
5459/// The state machine provides the `state` property for inspecting the current
5560/// state and the `handleEvent` method for triggering state transitions
5661/// defined in the schema.
@@ -83,7 +88,8 @@ public final class StateMachine<T: StateMachineSchemaType> {
8388 }
8489
8590 /// A method for triggering transitions and changing the state of the
86- /// machine. If the transition logic of the schema defines a transition
91+ /// machine. Transitions are not performed when a weak reference to the subject
92+ /// becomes `nil`. If the transition logic of the schema defines a transition
8793 /// for current state and given event, the state is changed, the optional
8894 /// transition block is executed, and `didTransitionCallback` is called.
8995 public func handleEvent( event: T . Event ) {
@@ -104,6 +110,10 @@ public final class StateMachine<T: StateMachineSchemaType> {
104110
105111
106112public extension StateMachine where T. Subject: AnyObject {
113+ /// Creates a state machine with a weak reference to a subject. This helps
114+ /// to remove subject-machine reference cycles, but it also means you have
115+ /// to keep a strong reference to a subject somewhere else. When subject
116+ /// reference becomes `nil`, transitions are no longer performed.
107117 public convenience init ( schema: T , subject: T . Subject ) {
108118 self . init ( schema: schema, subject: { [ weak subject] in subject } )
109119 }
0 commit comments