From 13113c50ed120901b8b1cf1d5a2285fd93af72e1 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 15 Jul 2022 12:24:40 -0400 Subject: [PATCH] behavior transcendence --- MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift | 2 +- .../Protocols/PageBehaviorHandlerProtocol.swift | 9 +++++++-- MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift | 7 +++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift index ba1db7fb..144001bc 100644 --- a/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/TemplateProtocol.swift @@ -42,7 +42,7 @@ public extension TemplateProtocol { behaviorHandlerModel.traverseAndAddRequiredBehaviors() behaviorHandler.createBehaviors(for: behaviorHandlerModel, delegateObject: delegateObject) if let viewController = self as? UIViewController { - MVMCoreUISession.sharedGlobal()?.applyGlobalBehaviors(to: (viewController)) + MVMCoreUISession.sharedGlobal()?.applyGlobalBehaviors(to: viewController) } } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift index 79f3364f..971a052b 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift @@ -14,12 +14,17 @@ public protocol PageBehaviorHandlerProtocol { public extension PageBehaviorHandlerProtocol { /// Creates the behaviors and sets the variable. mutating func createBehaviors(for model: PageBehaviorHandlerModelProtocol, delegateObject: MVMCoreUIDelegateObject?) { - guard let behaviorModels = model.behaviors else { + + behaviors = behaviors?.filter { $0.transcendsPageUpdates } + if behaviors?.isEmpty ?? false { behaviors = nil + } + + guard let behaviorModels = model.behaviors else { return } - var behaviors: [PageBehaviorProtocol] = [] + var behaviors: [PageBehaviorProtocol] = behaviors ?? [] for behaviorModel in behaviorModels { do { diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index 2e8fbd69..453041c2 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -9,10 +9,17 @@ public protocol PageBehaviorProtocol: ModelHandlerProtocol { + /// Should the behavior persist regardless of page behavior model updates. + var transcendsPageUpdates: Bool { get } + /// Initializes the behavior with the model init(model: PageBehaviorModelProtocol, delegateObject: MVMCoreUIDelegateObject?) } +public extension PageBehaviorProtocol { + var transcendsPageUpdates: Bool { return false } +} + /** Behavior conforming protocols. Behaviors will conform to one or more of these protocols to receive page lifecycle events that pertain to them. */