getbox 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
Callers know the type of the value they need, but not how it will be derived. The box resolves constructors lazily and caches instances automatically.
|
|
8
8
|
|
|
9
|
-
For an alternative pattern using AsyncLocalStorage where classes can resolve dependencies directly in their constructors, see [getbox/context](./CONTEXT.md).
|
|
10
|
-
|
|
11
9
|
## Installation
|
|
12
10
|
|
|
13
11
|
```sh
|
|
@@ -16,7 +14,9 @@ npm install getbox
|
|
|
16
14
|
|
|
17
15
|
## Usage
|
|
18
16
|
|
|
19
|
-
`getbox` has a very small API surface. You typically only need
|
|
17
|
+
`getbox` has a very small API surface. You typically only need `box.get()` and optionally `static init` or the `factory` helper.
|
|
18
|
+
|
|
19
|
+
For an alternative pattern using AsyncLocalStorage where classes can resolve dependencies directly in their constructors, see [getbox/context](./CONTEXT.md).
|
|
20
20
|
|
|
21
21
|
### Create a class
|
|
22
22
|
|
|
@@ -33,11 +33,11 @@ export class Printer {
|
|
|
33
33
|
|
|
34
34
|
### Use in another class
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
The `static init` property tells the box what dependencies to pass when instantiating the class.
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
39
|
// office.ts
|
|
40
|
-
import { Box
|
|
40
|
+
import { Box } from "getbox";
|
|
41
41
|
import { Printer } from "./printer";
|
|
42
42
|
|
|
43
43
|
export class Office {
|
|
@@ -103,14 +103,12 @@ export interface Logger {
|
|
|
103
103
|
log(message: string): void;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
export class ConsoleLogger implements Logger {
|
|
107
|
-
log(message: string): void {
|
|
108
|
-
console.log(`[LOG] ${message}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
106
|
const LoggerFactory = factory((box: Box): Logger => {
|
|
113
|
-
return
|
|
107
|
+
return {
|
|
108
|
+
log(message: string): void {
|
|
109
|
+
console.log(`[LOG] ${message}`);
|
|
110
|
+
},
|
|
111
|
+
};
|
|
114
112
|
});
|
|
115
113
|
```
|
|
116
114
|
|