Skip to content

Commit f5b0a1d

Browse files
authored
Updated interop documentation for FIRLibrary. (#2225)
1 parent 7c53489 commit f5b0a1d

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

Interop/Firebase Component System.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,42 @@ The Swift names are identical but dropping the `FIR` prefix.
7575
offered, dependencies, and a block for Core to instantiate it.
7676
- `@class FIRComponentContainer`
7777
- A container that holds different components that are registered with Core.
78-
- `@protocol FIRComponentRegistrant`
79-
- Describes functionality for frameworks registering components in the `FIRComponentContainer`. It
80-
allows Core to fetch components lazily from the implementing framework.
8178
- `#define FIR_COMPONENT(protocol, container)` (macro)
8279
- The macro to request an instance conforming to a given protocol from a container. Due to
8380
Objective-C's lightweight generic system, the safest and most readable API is provided by a
8481
macro that uses internal types to give compiler warnings if a developer tries to assign the
8582
result to a variable with the incorrect type.
83+
- `@protocol FIRLibrary`
84+
- Describes functionality for frameworks registering components in the `FIRComponentContainer` as
85+
well as other Core configuration functionality. It allows Core to fetch components lazily from
86+
the implementing framework.
87+
8688

8789
## Registering with Core
8890

8991
Each Firebase framework should register with Core in the `+load` method of the class conforming to
90-
`FIRComponentRegistrant`. This needs to happen at `+load` time because Core needs to resolve any
92+
`FIRLibrary`. This needs to happen at `+load` time because Core needs to resolve any
9193
dependencies before a class has a chance to be called by a developer (if called at all).
9294

9395
```
96+
#import <FirebaseCore/FIRAppInternal.h>
9497
#import <FirebaseCore/FIRComponentContainer.h>
95-
#import <FirebaseCore/FIRComponentRegistrant.h>
98+
#import <FirebaseCore/FIRLibrary.h>
9699
97-
@interface FIRFoo <FIRComponentRegistrant>
100+
@interface FIRFoo <FIRLibrary>
98101
@end
99102
100103
@implementation FIRFoo
101104
102105
+ (void)load {
103-
// Register with Core's container.
104-
[FIRComponentContainer registerAsComponentRegistrant:self];
106+
// Register with Core as a library. The version should be fetched from a constant defined
107+
// elsewhere, but that's not covered or relevant for this example.
108+
[FIRApp registerInternalLibrary:self
109+
withName:"fire-foo"
110+
withVersion:"1.0.0"];
105111
}
106112
107-
// TODO: Conform to `FIRComponentRegistrant`. See later sections for more information.
113+
// TODO: Conform to `FIRLibrary`. See later sections for more information.
108114
109115
@end
110116
```
@@ -131,20 +137,21 @@ it. It has a private, empty protocol that it uses to register with the container
131137
an example:
132138

133139
```
134-
// FIRFunctions.h
140+
// FIRFunctions.m
135141
136142
/// Empty protocol to register Functions as a component with Core.
137143
@protocol FIRFunctionsInstanceProvider
138144
@end
139145
140146
/// Privately conform to the protocol for component registration.
141-
@interface FIRFunctions () <FIRFunctionsInstanceProvider, FIRComponentRegistrant>
147+
@interface FIRFunctions () <FIRFunctionsInstanceProvider, FIRLibrary>
142148
@end
143149
144150
@implementation FIRFunctions
145151
146152
+ (void)load {
147-
[FIRComponentContainer registerAsComponentRegistrant:self];
153+
NSString *version = <# Fetch the version here #>;
154+
[FIRApp registerInternalLibrary:self withName:"fire-fun" withVersion:version];
148155
}
149156
150157
/// The array of components to register with Core. Since Functions is a leaf node and
@@ -207,9 +214,15 @@ could conform to and provide to other frameworks:
207214
// FIRAuth.m in the FirebaseAuth framework.
208215
209216
/// Privately conform to the protocol for interop and component registration.
210-
@interface FIRAuth () <FIRAuthInteroperable, FIRComponentRegistrant>
217+
@interface FIRAuth () <FIRAuthInteroperable, FIRLibrary>
211218
@end
212219
220+
+ (void)load {
221+
// Remember to register in +load!
222+
NSString *version = <# Fetch the version here #>;
223+
[FIRApp registerInternalLibrary:self withName:"fire-auth" withVersion:version];
224+
}
225+
213226
/// The components to register with Core.
214227
+ (NSArray<FIRComponent *> *)componentsToRegister {
215228
// Provide a component that will return an instance of `FIRAuth`.
@@ -258,8 +271,7 @@ separate class to keep `Firestore.m` cleaner.
258271

259272
```
260273
/// A concrete implementation for FSTFirestoreMultiDBProvider to create Firestore instances.
261-
@interface FSTFirestoreComponent : NSObject <FSTFirestoreMultiDBProvider,
262-
FIRComponentRegistrant>
274+
@interface FSTFirestoreComponent : NSObject <FSTFirestoreMultiDBProvider, FIRLibrary>
263275
264276
/// The `FIRApp` that instances will be set up with.
265277
@property(nonatomic, weak, readonly) FIRApp *app;
@@ -281,8 +293,9 @@ separate class to keep `Firestore.m` cleaner.
281293
@synthesize instances = _instances;
282294
283295
+ (void)load {
284-
// Don't forget to register!
285-
[FIRComponentContainer registerAsComponentRegistrant:self];
296+
// Remember to register in +load!
297+
NSString *version = <# Fetch the version here #>;
298+
[FIRApp registerInternalLibrary:self withName:"fire-fst" withVersion:version];
286299
}
287300
288301
- (instancetype)initWithApp:(FIRApp *)app {
@@ -299,7 +312,7 @@ separate class to keep `Firestore.m` cleaner.
299312
// Regular initialization code to create Firestore instances with required parameters...
300313
}
301314
302-
// `FIRComponentRegistrant` conformance.
315+
// `FIRLibrary` conformance.
303316
+ (NSArray<FIRComponent *> *)componentsToRegister {
304317
// Ignore any dependencies for simplicity in this example.
305318
FIRComponentCreationBlock creationBlock =

0 commit comments

Comments
 (0)