@joist/di 2.0.0-next.7 → 2.0.0-next.8

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 CHANGED
@@ -11,7 +11,7 @@ npm i @joist/di
11
11
  #### Example:
12
12
 
13
13
  ```TS
14
- import { Injector, inject } from '@joist/di';
14
+ import { Injector } from '@joist/di';
15
15
 
16
16
  class FooService {
17
17
  sayHello() {
@@ -20,7 +20,9 @@ class FooService {
20
20
  }
21
21
 
22
22
  class BarService {
23
- constructor(@inject(FooService) private foo: FooService) {}
23
+ static deps = [FooService];
24
+
25
+ constructor(private foo: FooService) {}
24
26
 
25
27
  sayHello() {
26
28
  return this.foo.sayHello();
@@ -44,7 +46,9 @@ class FooService {
44
46
  }
45
47
 
46
48
  class BarService {
47
- constructor(@inject(FooService) private foo: FooService) {}
49
+ static deps = [FooService];
50
+
51
+ constructor(private foo: FooService) {}
48
52
 
49
53
  sayHello() {
50
54
  return 'Hello From BarService and ' + this.foo.sayHello();
@@ -75,7 +79,7 @@ If you have nested injectors and you want to make sure the same instance is prov
75
79
  ```TS
76
80
  import { service } from '@joist/di';
77
81
 
78
- @service()
82
+ @service
79
83
  class FooService {
80
84
  sayHello() {
81
85
  return 'Hello From FooService';
@@ -89,21 +93,23 @@ Joist DI was built with custom elements in mind. Custom elements are an example
89
93
 
90
94
  Since the browser will be what initializes your custom elements we need to be able to tell the browser how to pass arguments.
91
95
 
92
- The `@injectable()` decorator allows the Joist Dependency Injector to pass arguments to your custom element when instances of your element is created.
96
+ The `@injectable` decorator allows the Joist Dependency Injector to pass arguments to your custom element when instances of your element is created.
93
97
 
94
- `@injectable()` is on required when you will not be able to manually create instances via an injector.
98
+ `@injectable` is on required when you will not be able to manually create instances via an injector.
95
99
 
96
100
  #### Inject dependency into your custom element constructor
97
101
 
98
102
  ```TS
99
103
  import { inject, service, injectable } from '@joist/di';
100
104
 
101
- @service()
105
+ @service
102
106
  class MyService {}
103
107
 
104
- @injectable()
108
+ @injectable
105
109
  class MyElement extends HTMLElement {
106
- constructor(@inject(MyService) public myService: MyService) {}
110
+ static deps = [MyService];
111
+
112
+ constructor(public myService: MyService) {}
107
113
  }
108
114
 
109
115
  customElements.define('my-element', MyElement);
@@ -129,9 +135,11 @@ defineEnvironment([
129
135
  }
130
136
  ]);
131
137
 
132
- @injectable()
138
+ @injectable
133
139
  class MyElement extends HTMLElement {
134
- constructor(@inject(Config) config: Config) {
140
+ static deps = [Config];
141
+
142
+ constructor(config: Config) {
135
143
  console.log(config.apiUrl); // http://real-api/api/
136
144
  }
137
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joist/di",
3
- "version": "2.0.0-next.7",
3
+ "version": "2.0.0-next.8",
4
4
  "main": "./target/build/lib.js",
5
5
  "module": "./target/build/lib.js",
6
6
  "exports": {
@@ -34,5 +34,5 @@
34
34
  "test": "tsc -p tsconfig.test.json && wtr --config ../../wtr.config.mjs --port 8001",
35
35
  "build": "tsc -p tsconfig.build.json"
36
36
  },
37
- "gitHead": "48190a6eb436c5dcfd6f5b0b358e78d7722c577e"
37
+ "gitHead": "1212ee3fec6c88bed79dc5ff97076c088f91c852"
38
38
  }
@@ -1,2 +1,2 @@
1
1
  import { ProviderToken } from '../lib/provider';
2
- export declare function service(provider: ProviderToken<any>): void;
2
+ export declare function service(provider: ProviderToken<any>): ProviderToken<any>;
@@ -1,4 +1,5 @@
1
1
  export function service(provider) {
2
2
  Object.defineProperty(provider, 'provideInRoot', { value: true });
3
+ return provider;
3
4
  }
4
5
  //# sourceMappingURL=service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../lib/service.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAC,QAA4B;IAClD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACpE,CAAC"}
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../lib/service.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAC,QAA4B;IAClD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAElE,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,2 +0,0 @@
1
- import { ProviderToken } from '../lib/provider';
2
- export declare function inject(injectable: ProviderToken<any>): (target: any, _: string, index: number) => void;
@@ -1,8 +0,0 @@
1
- import { PROVIDER_DEPS_KEY } from '../lib/utils';
2
- export function inject(injectable) {
3
- return function (target, _, index) {
4
- target[PROVIDER_DEPS_KEY] = target[PROVIDER_DEPS_KEY] || [];
5
- target[PROVIDER_DEPS_KEY][index] = injectable;
6
- };
7
- }
8
- //# sourceMappingURL=inject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../lib/inject.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,UAAU,MAAM,CAAC,UAA8B;IACnD,OAAO,UAAU,MAAW,EAAE,CAAS,EAAE,KAAa;QACpD,MAAM,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;QAC5D,MAAM,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC"}