Skip to content

Commit c770509

Browse files
vkryachkorlazo
andauthored
Apply suggestions from code review
Co-authored-by: Rodrigo Lazo <[email protected]>
1 parent 9e72809 commit c770509

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

contributor-docs/components/dependencies.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ parent: Firebase Components
88
1. TOC
99
{:toc}
1010

11-
This page gives an overview of various different dependency types supported by the Components Framework.
11+
This page gives an overview of the different dependency types supported by the Components Framework.
1212

1313
## Background
1414

1515
As discussed in [Firebase Components]({{ site.baseurl }}{% link components/components.md %}), in order
16-
for a `Component` to be injected with the things it needs to function, it needs to declare dependencies.
16+
for a `Component` to be injected with the things it needs to function, it has to declare its dependencies.
1717
These dependencies are then made available and injected into `Components` at runtime.
1818

19-
Firebase Components provide different types of dependencies
19+
Firebase Components provide different types of dependencies.
2020

2121
## Lazy vs Eager dependencies
2222

23-
When it comes to initializing a given component, there are 2 ways to provide its dependencies to it.
23+
When it comes to initialize a component, there are 2 ways of provide its dependencies.
2424

2525
### Direct Injection
2626

@@ -35,14 +35,14 @@ class MyComponent(private val dep : MyDep) {
3535
```
3636

3737
As you can see above the component's dependency is passed by value directly,
38-
which means that the dependency component needs to have fully initialized before
38+
which means that the dependency needs to be fully initialized before
3939
it's handed off to the requesting component. As a result `MyComponent` may have to pay the cost
40-
of `MyDep` initialization just to be able to be created.
40+
of initializing `MyDep` just to be created.
4141

4242
### Lazy/Provider Injection
4343

44-
With this type of injection, instead of getting and instance of the dependency directly, the dependency
45-
is passed into the `Component` with the help of the `com.google.firebase.inject.Provider`
44+
With this type of injection, instead of getting an instance of the dependency directly, the dependency
45+
is passed into the `Component` with the help of a `com.google.firebase.inject.Provider`
4646

4747
```java
4848
public interface Provider<T> { T get(); }
@@ -58,17 +58,17 @@ class MyComponent(private val dep : Provider<MyDep>) {
5858
}
5959
```
6060

61-
On the surface this does not look like a big change, but it has an important side effect where,
62-
in order to create an instance of `MyComponent`, there is no need to initialize `MyDep` and instead
63-
to delay it until it's actually needed.
61+
On the surface this does not look like a big change, but it has an important side effect. In order to create
62+
an instance of `MyComponent`, we don't need to initialize `MyDep` anymore. Instead, initialization can be
63+
delayed until `MyDep` is actually used.
6464

6565
It is also benefitial to use a `Provider` in the context of [Play's dynamic feature delivery](https://developer.android.com/guide/playcore/feature-delivery).
6666
See [Dynamic Module Support]({{ site.baseurl }}{% link components/dynamic_modules.md %}) for more details.
6767

6868
## Required dependencies
6969

7070
This type of dependency informs the `ComponentRuntime` that a given `Component` cannot function without a dependency.
71-
When the dependency is missing during initialization, `ComponentRuntime` will throw a `DependencyMissingDependency`.
71+
When the dependency is missing during initialization, `ComponentRuntime` will throw a `MissingDependencyException`.
7272
This type of dependency is useful for built-in components that are always present like `Context`, `FirebaseApp`,
7373
`FirebaseOptions`, [Executors]({{ site.baseurl }}{% link components/executors.md %}).
7474

@@ -89,7 +89,7 @@ This type of dependencies is useful when your `Component` can operate normally w
8989
available, but can have enhanced functionality when present. e.g. `Firestore` can work without `Auth` but
9090
provides secure database access when `Auth` is present.
9191

92-
To declare a required dependency use the following in your `ComponentRegistrar`:
92+
To declare an optional dependency use the following in your `ComponentRegistrar`:
9393

9494
```java
9595
.add(Dependency.optionalProvider(MyDep.class))
@@ -101,19 +101,18 @@ The provider will return `null` if the dependency is not present in the app.
101101

102102
{: .warning }
103103
When the app uses [Play's dynamic feature delivery](https://developer.android.com/guide/playcore/feature-delivery),
104-
`provider.get()` can return your dependency when it becomes available, so be prepared for that.
105-
And don't store references to the result of `provider.get()` calls.
104+
`provider.get()` will return your dependency when it becomes available. To support this use case, don't store references to the result of `provider.get()` calls.
106105

107106
See [Dynamic Module Support]({{ site.baseurl }}{% link components/dynamic_modules.md %}) for details
108107

109108
{: .warning }
110-
See Deferred dependencies if you your dependency has a callback based apis
109+
See Deferred dependencies if you your dependency has a callback based API
111110

112111
## Deferred Dependencies
113112

114113
Useful for optional dependencies which have a listener-style API, i.e. the dependent component registers a
115-
listener with the dependency and never calls it again(instead the dependency will call the registered listener).
116-
A good example is `Firestore`'s use of `Auth` where `Firestore` registers a token change listener to get
114+
listener with the dependency and never calls it again (instead the dependency will call the registered listener).
115+
A good example is `Firestore`'s use of `Auth`, where `Firestore` registers a token change listener to get
117116
notified when a new token is available. The problem is that when `Firestore` initializes, `Auth` may not be
118117
present in the app, and is instead part of a dynamic module that can be loaded at runtime on demand.
119118

@@ -130,7 +129,7 @@ public interface Deferred<T> {
130129
}
131130
```
132131

133-
To use it a component needs to use `Dependency.deferred(SomeType.class)`:
132+
To use it a component needs to call `Dependency.deferred(SomeType.class)`:
134133

135134
```kotlin
136135
class MyComponent(deferred: Deferred<SomeType>) {

0 commit comments

Comments
 (0)