@viewfly/core 1.0.0-alpha.2 → 1.0.0-alpha.4

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.
@@ -22,5 +22,5 @@ export type ExtractValueType<T> = T extends Type<any> ? InstanceType<T> : T exte
22
22
  */
23
23
  export declare abstract class Injector {
24
24
  abstract parentInjector: Injector | null;
25
- abstract get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
25
+ abstract get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
26
26
  }
@@ -37,7 +37,7 @@ export declare const Optional: OptionalDecorator;
37
37
  export interface Prop {
38
38
  }
39
39
  export interface PropDecorator {
40
- <T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token?: T | ForwardRef<ExtractValueType<T>>, flags?: InjectFlags, notFoundValue?: U): PropertyDecorator;
40
+ <T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token?: T | ForwardRef<ExtractValueType<T>>, notFoundValue?: U, flags?: InjectFlags): PropertyDecorator;
41
41
  new (token: any): Prop;
42
42
  }
43
43
  export declare const Prop: PropDecorator;
@@ -2,5 +2,5 @@ import { InjectFlags, Injector } from './injector';
2
2
  export declare const THROW_IF_NOT_FOUND: any;
3
3
  export declare class NullInjector extends Injector {
4
4
  parentInjector: null;
5
- get(token: any, flag?: InjectFlags, notFoundValue?: any): any;
5
+ get(token: any, notFoundValue?: any, _?: InjectFlags): any;
6
6
  }
@@ -17,10 +17,10 @@ export declare class ReflectiveInjector extends Injector {
17
17
  /**
18
18
  * 用于获取当前注入器上下文内的实例、对象或数据
19
19
  * @param token 访问 token
20
- * @param flags 查询规则
21
20
  * @param notFoundValue 如未查找到的返回值
21
+ * @param flags 查询规则
22
22
  */
23
- get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
23
+ get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
24
24
  private getValue;
25
25
  /**
26
26
  * 解决并获取依赖参数
@@ -33,7 +33,7 @@ export declare class Component extends ReflectiveInjector {
33
33
  template: any;
34
34
  portalHost: import("./injection-tokens").NativeNode | undefined;
35
35
  };
36
- update(newProps: Props, forceUpdate?: boolean): any;
36
+ update(newProps: Record<string, any>, forceUpdate?: boolean): any;
37
37
  provide<T>(providers: Provider<T> | Provider<T>[]): void;
38
38
  rendered(): void;
39
39
  destroy(): void;
@@ -237,7 +237,7 @@ export declare function withAnnotation<T extends JSXInternal.ComponentSetup>(ann
237
237
  /**
238
238
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
239
239
  */
240
- export declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
240
+ export declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
241
241
  /**
242
242
  * 获取当前组件实例
243
243
  */
@@ -1,8 +1,6 @@
1
1
  import { ListenDelegate } from './_utils';
2
2
  export interface Props {
3
3
  children?: JSXInternal.ViewNode | JSXInternal.ViewNode[];
4
- [key: string]: any;
5
- [key: symbol]: any;
6
4
  }
7
5
  export declare function Fragment(props: Props): () => any;
8
6
  export type Key = number | string;
@@ -161,6 +161,40 @@ var InjectFlags;
161
161
  class Injector {
162
162
  }
163
163
 
164
+ /**
165
+ * 构造函数参数装饰器,用于改变注入 token
166
+ */
167
+ const Inject = function InjectDecorator(token) {
168
+ if (this instanceof Inject) {
169
+ this.token = token;
170
+ }
171
+ else {
172
+ return makeParamDecorator(Inject, new Inject(token));
173
+ }
174
+ };
175
+ const Self = function SelfDecorator() {
176
+ if (!(this instanceof Self)) {
177
+ return makeParamDecorator(Self, new Self());
178
+ }
179
+ };
180
+ const SkipSelf = function SkipSelfDecorator() {
181
+ if (!(this instanceof SkipSelf)) {
182
+ return makeParamDecorator(SkipSelf, new SkipSelf());
183
+ }
184
+ };
185
+ const Optional = function OptionalDecorator() {
186
+ if (!(this instanceof Optional)) {
187
+ return makeParamDecorator(Optional, new Optional());
188
+ }
189
+ };
190
+ const Prop = function PropDecorator(token, notFoundValue, flags) {
191
+ if (!(this instanceof Prop)) {
192
+ return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
193
+ instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, notFoundValue, flags);
194
+ });
195
+ }
196
+ };
197
+
164
198
  function stringify(token) {
165
199
  if (typeof token === 'string') {
166
200
  return token;
@@ -205,7 +239,8 @@ class NullInjector extends Injector {
205
239
  super(...arguments);
206
240
  this.parentInjector = null;
207
241
  }
208
- get(token, flag, notFoundValue = THROW_IF_NOT_FOUND) {
242
+ /* eslint-disable-next-line */
243
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
209
244
  if (notFoundValue === THROW_IF_NOT_FOUND) {
210
245
  throw nullInjectorErrorFn(token);
211
246
  }
@@ -213,40 +248,6 @@ class NullInjector extends Injector {
213
248
  }
214
249
  }
215
250
 
216
- /**
217
- * 构造函数参数装饰器,用于改变注入 token
218
- */
219
- const Inject = function InjectDecorator(token) {
220
- if (this instanceof Inject) {
221
- this.token = token;
222
- }
223
- else {
224
- return makeParamDecorator(Inject, new Inject(token));
225
- }
226
- };
227
- const Self = function SelfDecorator() {
228
- if (!(this instanceof Self)) {
229
- return makeParamDecorator(Self, new Self());
230
- }
231
- };
232
- const SkipSelf = function SkipSelfDecorator() {
233
- if (!(this instanceof SkipSelf)) {
234
- return makeParamDecorator(SkipSelf, new SkipSelf());
235
- }
236
- };
237
- const Optional = function OptionalDecorator() {
238
- if (!(this instanceof Optional)) {
239
- return makeParamDecorator(Optional, new Optional());
240
- }
241
- };
242
- const Prop = function PropDecorator(token, flags, notFoundValue = THROW_IF_NOT_FOUND) {
243
- if (!(this instanceof Prop)) {
244
- return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
245
- instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, flags, notFoundValue);
246
- });
247
- }
248
- };
249
-
250
251
  /**
251
252
  * 标准化 provide,并返回统一数据结构
252
253
  * @param provider
@@ -424,15 +425,15 @@ class ReflectiveInjector extends Injector {
424
425
  /**
425
426
  * 用于获取当前注入器上下文内的实例、对象或数据
426
427
  * @param token 访问 token
427
- * @param flags 查询规则
428
428
  * @param notFoundValue 如未查找到的返回值
429
+ * @param flags 查询规则
429
430
  */
430
- get(token, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
431
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
431
432
  var _a;
432
433
  flags = flags || InjectFlags.Default;
433
434
  if (flags === InjectFlags.SkipSelf) {
434
435
  if (this.parentInjector) {
435
- return this.parentInjector.get(token, InjectFlags.Default, notFoundValue);
436
+ return this.parentInjector.get(token, notFoundValue);
436
437
  }
437
438
  if (notFoundValue !== THROW_IF_NOT_FOUND) {
438
439
  return notFoundValue;
@@ -476,9 +477,12 @@ class ReflectiveInjector extends Injector {
476
477
  return notFoundValue;
477
478
  }
478
479
  if (this.parentInjector) {
479
- return this.parentInjector.get(token, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default, notFoundValue);
480
+ return this.parentInjector.get(token, notFoundValue, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default);
480
481
  }
481
482
  if (notFoundValue === THROW_IF_NOT_FOUND) {
483
+ // if (flags === InjectFlags.Optional) {
484
+ // return null as U
485
+ // }
482
486
  throw reflectiveInjectorErrorFn(token);
483
487
  }
484
488
  return notFoundValue;
@@ -508,11 +512,11 @@ class ReflectiveInjector extends Injector {
508
512
  const tryValue = {};
509
513
  const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
510
514
  if (dep.visibility instanceof Self) {
511
- reflectiveValue = this.get(injectToken, InjectFlags.Self, tryValue);
515
+ reflectiveValue = this.get(injectToken, tryValue, InjectFlags.Self);
512
516
  }
513
517
  else if (dep.visibility instanceof SkipSelf) {
514
518
  if (this.parentInjector) {
515
- reflectiveValue = this.parentInjector.get(injectToken, InjectFlags.Default, tryValue);
519
+ reflectiveValue = this.parentInjector.get(injectToken, tryValue);
516
520
  }
517
521
  else {
518
522
  if (dep.optional) {
@@ -525,7 +529,7 @@ class ReflectiveInjector extends Injector {
525
529
  }
526
530
  }
527
531
  else {
528
- reflectiveValue = this.get(injectToken, InjectFlags.Default, tryValue);
532
+ reflectiveValue = this.get(injectToken, tryValue);
529
533
  }
530
534
  if (reflectiveValue === tryValue) {
531
535
  if (dep.optional) {
@@ -843,7 +847,12 @@ class Component extends ReflectiveInjector {
843
847
  }
844
848
  }
845
849
  if (unmountedCallbacks.length) {
846
- this.unmountedCallbacks = unmountedCallbacks;
850
+ if (this.unmountedCallbacks) {
851
+ this.unmountedCallbacks.push(...unmountedCallbacks);
852
+ }
853
+ else {
854
+ this.unmountedCallbacks = unmountedCallbacks;
855
+ }
847
856
  }
848
857
  this.mountCallbacks = null;
849
858
  }
@@ -1232,9 +1241,9 @@ function withAnnotation(annotation, componentSetup) {
1232
1241
  /**
1233
1242
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
1234
1243
  */
1235
- function inject(token, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
1244
+ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1236
1245
  const component = getSetupContext();
1237
- return component.get(token, flags, notFoundValue);
1246
+ return component.get(token, notFoundValue, flags);
1238
1247
  }
1239
1248
  /**
1240
1249
  * 获取当前组件实例
package/bundles/index.js CHANGED
@@ -163,6 +163,40 @@ exports.InjectFlags = void 0;
163
163
  class Injector {
164
164
  }
165
165
 
166
+ /**
167
+ * 构造函数参数装饰器,用于改变注入 token
168
+ */
169
+ const Inject = function InjectDecorator(token) {
170
+ if (this instanceof Inject) {
171
+ this.token = token;
172
+ }
173
+ else {
174
+ return makeParamDecorator(Inject, new Inject(token));
175
+ }
176
+ };
177
+ const Self = function SelfDecorator() {
178
+ if (!(this instanceof Self)) {
179
+ return makeParamDecorator(Self, new Self());
180
+ }
181
+ };
182
+ const SkipSelf = function SkipSelfDecorator() {
183
+ if (!(this instanceof SkipSelf)) {
184
+ return makeParamDecorator(SkipSelf, new SkipSelf());
185
+ }
186
+ };
187
+ const Optional = function OptionalDecorator() {
188
+ if (!(this instanceof Optional)) {
189
+ return makeParamDecorator(Optional, new Optional());
190
+ }
191
+ };
192
+ const Prop = function PropDecorator(token, notFoundValue, flags) {
193
+ if (!(this instanceof Prop)) {
194
+ return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
195
+ instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, notFoundValue, flags);
196
+ });
197
+ }
198
+ };
199
+
166
200
  function stringify(token) {
167
201
  if (typeof token === 'string') {
168
202
  return token;
@@ -207,7 +241,8 @@ class NullInjector extends Injector {
207
241
  super(...arguments);
208
242
  this.parentInjector = null;
209
243
  }
210
- get(token, flag, notFoundValue = THROW_IF_NOT_FOUND) {
244
+ /* eslint-disable-next-line */
245
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
211
246
  if (notFoundValue === THROW_IF_NOT_FOUND) {
212
247
  throw nullInjectorErrorFn(token);
213
248
  }
@@ -215,40 +250,6 @@ class NullInjector extends Injector {
215
250
  }
216
251
  }
217
252
 
218
- /**
219
- * 构造函数参数装饰器,用于改变注入 token
220
- */
221
- const Inject = function InjectDecorator(token) {
222
- if (this instanceof Inject) {
223
- this.token = token;
224
- }
225
- else {
226
- return makeParamDecorator(Inject, new Inject(token));
227
- }
228
- };
229
- const Self = function SelfDecorator() {
230
- if (!(this instanceof Self)) {
231
- return makeParamDecorator(Self, new Self());
232
- }
233
- };
234
- const SkipSelf = function SkipSelfDecorator() {
235
- if (!(this instanceof SkipSelf)) {
236
- return makeParamDecorator(SkipSelf, new SkipSelf());
237
- }
238
- };
239
- const Optional = function OptionalDecorator() {
240
- if (!(this instanceof Optional)) {
241
- return makeParamDecorator(Optional, new Optional());
242
- }
243
- };
244
- const Prop = function PropDecorator(token, flags, notFoundValue = THROW_IF_NOT_FOUND) {
245
- if (!(this instanceof Prop)) {
246
- return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
247
- instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, flags, notFoundValue);
248
- });
249
- }
250
- };
251
-
252
253
  /**
253
254
  * 标准化 provide,并返回统一数据结构
254
255
  * @param provider
@@ -426,15 +427,15 @@ class ReflectiveInjector extends Injector {
426
427
  /**
427
428
  * 用于获取当前注入器上下文内的实例、对象或数据
428
429
  * @param token 访问 token
429
- * @param flags 查询规则
430
430
  * @param notFoundValue 如未查找到的返回值
431
+ * @param flags 查询规则
431
432
  */
432
- get(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
433
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
433
434
  var _a;
434
435
  flags = flags || exports.InjectFlags.Default;
435
436
  if (flags === exports.InjectFlags.SkipSelf) {
436
437
  if (this.parentInjector) {
437
- return this.parentInjector.get(token, exports.InjectFlags.Default, notFoundValue);
438
+ return this.parentInjector.get(token, notFoundValue);
438
439
  }
439
440
  if (notFoundValue !== THROW_IF_NOT_FOUND) {
440
441
  return notFoundValue;
@@ -478,9 +479,12 @@ class ReflectiveInjector extends Injector {
478
479
  return notFoundValue;
479
480
  }
480
481
  if (this.parentInjector) {
481
- return this.parentInjector.get(token, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default, notFoundValue);
482
+ return this.parentInjector.get(token, notFoundValue, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default);
482
483
  }
483
484
  if (notFoundValue === THROW_IF_NOT_FOUND) {
485
+ // if (flags === InjectFlags.Optional) {
486
+ // return null as U
487
+ // }
484
488
  throw reflectiveInjectorErrorFn(token);
485
489
  }
486
490
  return notFoundValue;
@@ -510,11 +514,11 @@ class ReflectiveInjector extends Injector {
510
514
  const tryValue = {};
511
515
  const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
512
516
  if (dep.visibility instanceof Self) {
513
- reflectiveValue = this.get(injectToken, exports.InjectFlags.Self, tryValue);
517
+ reflectiveValue = this.get(injectToken, tryValue, exports.InjectFlags.Self);
514
518
  }
515
519
  else if (dep.visibility instanceof SkipSelf) {
516
520
  if (this.parentInjector) {
517
- reflectiveValue = this.parentInjector.get(injectToken, exports.InjectFlags.Default, tryValue);
521
+ reflectiveValue = this.parentInjector.get(injectToken, tryValue);
518
522
  }
519
523
  else {
520
524
  if (dep.optional) {
@@ -527,7 +531,7 @@ class ReflectiveInjector extends Injector {
527
531
  }
528
532
  }
529
533
  else {
530
- reflectiveValue = this.get(injectToken, exports.InjectFlags.Default, tryValue);
534
+ reflectiveValue = this.get(injectToken, tryValue);
531
535
  }
532
536
  if (reflectiveValue === tryValue) {
533
537
  if (dep.optional) {
@@ -845,7 +849,12 @@ class Component extends ReflectiveInjector {
845
849
  }
846
850
  }
847
851
  if (unmountedCallbacks.length) {
848
- this.unmountedCallbacks = unmountedCallbacks;
852
+ if (this.unmountedCallbacks) {
853
+ this.unmountedCallbacks.push(...unmountedCallbacks);
854
+ }
855
+ else {
856
+ this.unmountedCallbacks = unmountedCallbacks;
857
+ }
849
858
  }
850
859
  this.mountCallbacks = null;
851
860
  }
@@ -1234,9 +1243,9 @@ function withAnnotation(annotation, componentSetup) {
1234
1243
  /**
1235
1244
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
1236
1245
  */
1237
- function inject(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
1246
+ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1238
1247
  const component = getSetupContext();
1239
- return component.get(token, flags, notFoundValue);
1248
+ return component.get(token, notFoundValue, flags);
1240
1249
  }
1241
1250
  /**
1242
1251
  * 获取当前组件实例
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -47,7 +47,7 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/viewfly/viewfly.git/issues"
49
49
  },
50
- "gitHead": "494829c8d0cde30d0a35c61351c863ea14515ac2",
50
+ "gitHead": "176e9fdb7415d029541a1da102001d9bab6c3319",
51
51
  "dependencies": {
52
52
  "reflect-metadata": "^0.1.13"
53
53
  }