You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.6 KiB

  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRApp;
  18. @class FIRComponentContainer;
  19. NS_ASSUME_NONNULL_BEGIN
  20. /// Provides a system to clean up cached instances returned from the component system.
  21. NS_SWIFT_NAME(ComponentLifecycleMaintainer)
  22. @protocol FIRComponentLifecycleMaintainer
  23. /// The associated app will be deleted, clean up any resources as they are about to be deallocated.
  24. - (void)appWillBeDeleted:(FIRApp *)app;
  25. @end
  26. typedef _Nullable id (^FIRComponentCreationBlock)(FIRComponentContainer *container,
  27. BOOL *isCacheable)
  28. NS_SWIFT_NAME(ComponentCreationBlock);
  29. @class FIRDependency;
  30. /// Describes the timing of instantiation. Note: new components should default to lazy unless there
  31. /// is a strong reason to be eager.
  32. typedef NS_ENUM(NSInteger, FIRInstantiationTiming) {
  33. FIRInstantiationTimingLazy,
  34. FIRInstantiationTimingAlwaysEager,
  35. FIRInstantiationTimingEagerInDefaultApp
  36. } NS_SWIFT_NAME(InstantiationTiming);
  37. /// A component that can be used from other Firebase SDKs.
  38. NS_SWIFT_NAME(Component)
  39. @interface FIRComponent : NSObject
  40. /// The protocol describing functionality provided from the Component.
  41. @property(nonatomic, strong, readonly) Protocol *protocol;
  42. /// The timing of instantiation.
  43. @property(nonatomic, readonly) FIRInstantiationTiming instantiationTiming;
  44. /// An array of dependencies for the component.
  45. @property(nonatomic, copy, readonly) NSArray<FIRDependency *> *dependencies;
  46. /// A block to instantiate an instance of the component with the appropriate dependencies.
  47. @property(nonatomic, copy, readonly) FIRComponentCreationBlock creationBlock;
  48. // There's an issue with long NS_SWIFT_NAMES that causes compilation to fail, disable clang-format
  49. // for the next two methods.
  50. // clang-format off
  51. /// Creates a component with no dependencies that will be lazily initialized.
  52. + (instancetype)componentWithProtocol:(Protocol *)protocol
  53. creationBlock:(FIRComponentCreationBlock)creationBlock
  54. NS_SWIFT_NAME(init(_:creationBlock:));
  55. /// Creates a component to be registered with the component container.
  56. ///
  57. /// @param protocol - The protocol describing functionality provided by the component.
  58. /// @param instantiationTiming - When the component should be initialized. Use .lazy unless there's
  59. /// a good reason to be instantiated earlier.
  60. /// @param dependencies - Any dependencies the `implementingClass` has, optional or required.
  61. /// @param creationBlock - A block to instantiate the component with a container, and if
  62. /// @return A component that can be registered with the component container.
  63. + (instancetype)componentWithProtocol:(Protocol *)protocol
  64. instantiationTiming:(FIRInstantiationTiming)instantiationTiming
  65. dependencies:(NSArray<FIRDependency *> *)dependencies
  66. creationBlock:(FIRComponentCreationBlock)creationBlock
  67. NS_SWIFT_NAME(init(_:instantiationTiming:dependencies:creationBlock:));
  68. // clang-format on
  69. /// Unavailable.
  70. - (instancetype)init NS_UNAVAILABLE;
  71. @end
  72. NS_ASSUME_NONNULL_END