Created
January 1, 2018 23:27
-
-
Save twittemb/8b59b2aee83221f488569fb968e1f957 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private var subjectContext: UInt8 = 0 | |
| /// a Stepper has only one purpose: emit Steps that correspond to | |
| /// specific navigation states. | |
| /// The state changes lead to navigation actions in the context of | |
| /// a specific Flow | |
| public protocol Stepper: Synchronizable { | |
| /// the Rx Obsersable that will trigger new Steps | |
| var steps: Observable<Step> { get } | |
| } | |
| public extension Stepper { | |
| /// The step in which to publish new Steps | |
| public var step: BehaviorSubject<Step> { | |
| return self.synchronized { | |
| if let subject = objc_getAssociatedObject(self, &subjectContext) | |
| as? BehaviorSubject<Step> { | |
| return subject | |
| } | |
| let newSubject = BehaviorSubject<Step>(value: NoStep()) | |
| objc_setAssociatedObject(self, | |
| &subjectContext, | |
| newSubject, | |
| .OBJC_ASSOCIATION_RETAIN_NONATOMIC) | |
| return newSubject | |
| } | |
| } | |
| /// the Rx Obsersable that will trigger new Steps | |
| public var steps: Observable<Step> { | |
| return self.step.asObservable() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment