FIRComponent.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef FIREBASECORE_FIRCOMPONENT_H
  17. #define FIREBASECORE_FIRCOMPONENT_H
  18. #import <Foundation/Foundation.h>
  19. @class FIRApp;
  20. @class FIRComponentContainer;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /// Provides a system to clean up cached instances returned from the component system.
  23. NS_SWIFT_NAME(ComponentLifecycleMaintainer)
  24. @protocol FIRComponentLifecycleMaintainer
  25. /// The associated app will be deleted, clean up any resources as they are about to be deallocated.
  26. - (void)appWillBeDeleted:(FIRApp *)app;
  27. @end
  28. typedef _Nullable id (^FIRComponentCreationBlock)(FIRComponentContainer *container,
  29. BOOL *isCacheable)
  30. NS_SWIFT_NAME(ComponentCreationBlock);
  31. /// Describes the timing of instantiation. Note: new components should default to lazy unless there
  32. /// is a strong reason to be eager.
  33. typedef NS_ENUM(NSInteger, FIRInstantiationTiming) {
  34. FIRInstantiationTimingLazy,
  35. FIRInstantiationTimingAlwaysEager,
  36. FIRInstantiationTimingEagerInDefaultApp
  37. } NS_SWIFT_NAME(InstantiationTiming);
  38. /// A component that can be used from other Firebase SDKs.
  39. NS_SWIFT_NAME(Component)
  40. @interface FIRComponent : NSObject
  41. /// The protocol describing functionality provided from the `Component`.
  42. @property(nonatomic, strong, readonly) Protocol *protocol;
  43. /// The timing of instantiation.
  44. @property(nonatomic, readonly) FIRInstantiationTiming instantiationTiming;
  45. /// A block to instantiate an instance of the component with the appropriate dependencies.
  46. @property(nonatomic, copy, readonly) FIRComponentCreationBlock creationBlock;
  47. // There's an issue with long NS_SWIFT_NAMES that causes compilation to fail, disable clang-format
  48. // for the next two methods.
  49. // clang-format off
  50. /// Creates a component with no dependencies that will be lazily initialized.
  51. + (instancetype)componentWithProtocol:(Protocol *)protocol
  52. creationBlock:(FIRComponentCreationBlock)creationBlock
  53. NS_SWIFT_NAME(init(_:creationBlock:));
  54. /// Creates a component to be registered with the component container.
  55. ///
  56. /// @param protocol - The protocol describing functionality provided by the component.
  57. /// @param instantiationTiming - When the component should be initialized. Use .lazy unless there's
  58. /// a good reason to be instantiated earlier.
  59. /// @param creationBlock - A block to instantiate the component with a container, and if
  60. /// @return A component that can be registered with the component container.
  61. + (instancetype)componentWithProtocol:(Protocol *)protocol
  62. instantiationTiming:(FIRInstantiationTiming)instantiationTiming
  63. creationBlock:(FIRComponentCreationBlock)creationBlock
  64. NS_SWIFT_NAME(init(_:instantiationTiming:creationBlock:));
  65. // clang-format on
  66. /// Unavailable.
  67. - (instancetype)init NS_UNAVAILABLE;
  68. @end
  69. NS_ASSUME_NONNULL_END
  70. #endif // FIREBASECORE_FIRCOMPONENT_H