StatefulPluggable.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // StatefulPluggable.swift
  3. // LoopKit
  4. //
  5. // Created by Nathaniel Hamming on 2023-09-05.
  6. // Copyright © 2023 LoopKit Authors. All rights reserved.
  7. //
  8. import Foundation
  9. public protocol StatefulPlugin {
  10. var pluginType: StatefulPluggable.Type? { get }
  11. }
  12. public protocol StatefulPluggableProvider {
  13. /// The stateful plugin with the specified identifier.
  14. ///
  15. /// - Parameters:
  16. /// - identifier: The identifier of the stateful plugin
  17. /// - Returns: Either a stateful plugin with matching identifier or nil.
  18. func statefulPlugin(withIdentifier identifier: String) -> StatefulPluggable?
  19. }
  20. public protocol StatefulPluggableDelegate: AnyObject {
  21. /// Informs the delegate that the state of the specified plugin was updated and the delegate should persist the plugin. May
  22. /// be invoked prior to the plugin completing setup.
  23. ///
  24. /// - Parameters:
  25. /// - plugin: The plugin that updated state.
  26. func pluginDidUpdateState(_ plugin: StatefulPluggable)
  27. /// Informs the delegate that the plugin wants deletion.
  28. ///
  29. /// - Parameters:
  30. /// - plugin: The plugin that wants deletion.
  31. func pluginWantsDeletion(_ plugin: StatefulPluggable)
  32. }
  33. public protocol StatefulPluggable: Pluggable {
  34. typealias RawStateValue = [String: Any]
  35. /// The delegate to notify of plugin updates.
  36. var stateDelegate: StatefulPluggableDelegate? { get set }
  37. /// Initializes the plugin with the previously-serialized state.
  38. ///
  39. /// - Parameters:
  40. /// - rawState: The previously-serialized state of the plugin.
  41. init?(rawState: RawStateValue)
  42. /// The current, serializable state of the plugin.
  43. var rawState: RawStateValue { get }
  44. /// Is the plugin onboarded and ready for use?
  45. var isOnboarded: Bool { get }
  46. }