FIRComponent.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /// Describes the timing of instantiation. Note: new components should default to lazy unless there
  30. /// is a strong reason to be eager.
  31. typedef NS_ENUM(NSInteger, FIRInstantiationTiming) {
  32. FIRInstantiationTimingLazy,
  33. FIRInstantiationTimingAlwaysEager,
  34. FIRInstantiationTimingEagerInDefaultApp
  35. } NS_SWIFT_NAME(InstantiationTiming);
  36. /// A component that can be used from other Firebase SDKs.
  37. NS_SWIFT_NAME(Component)
  38. @interface FIRComponent : NSObject
  39. /// The protocol describing functionality provided from the `Component`.
  40. @property(nonatomic, strong, readonly) Protocol *protocol;
  41. /// The timing of instantiation.
  42. @property(nonatomic, readonly) FIRInstantiationTiming instantiationTiming;
  43. /// A block to instantiate an instance of the component with the appropriate dependencies.
  44. @property(nonatomic, copy, readonly) FIRComponentCreationBlock creationBlock;
  45. // There's an issue with long NS_SWIFT_NAMES that causes compilation to fail, disable clang-format
  46. // for the next two methods.
  47. // clang-format off
  48. /// Creates a component with no dependencies that will be lazily initialized.
  49. + (instancetype)componentWithProtocol:(Protocol *)protocol
  50. creationBlock:(FIRComponentCreationBlock)creationBlock
  51. NS_SWIFT_NAME(init(_:creationBlock:));
  52. /// Creates a component to be registered with the component container.
  53. ///
  54. /// @param protocol - The protocol describing functionality provided by the component.
  55. /// @param instantiationTiming - When the component should be initialized. Use .lazy unless there's
  56. /// a good reason to be instantiated earlier.
  57. /// @param creationBlock - A block to instantiate the component with a container, and if
  58. /// @return A component that can be registered with the component container.
  59. + (instancetype)componentWithProtocol:(Protocol *)protocol
  60. instantiationTiming:(FIRInstantiationTiming)instantiationTiming
  61. creationBlock:(FIRComponentCreationBlock)creationBlock
  62. NS_SWIFT_NAME(init(_:instantiationTiming:creationBlock:));
  63. // clang-format on
  64. /// Unavailable.
  65. - (instancetype)init NS_UNAVAILABLE;
  66. @end
  67. NS_ASSUME_NONNULL_END