@viewfly/core 1.0.0-alpha.1 → 1.0.0-alpha.3

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
  * 解决并获取依赖参数
@@ -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
  */
@@ -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,7 @@ 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
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
209
243
  if (notFoundValue === THROW_IF_NOT_FOUND) {
210
244
  throw nullInjectorErrorFn(token);
211
245
  }
@@ -213,40 +247,6 @@ class NullInjector extends Injector {
213
247
  }
214
248
  }
215
249
 
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
250
  /**
251
251
  * 标准化 provide,并返回统一数据结构
252
252
  * @param provider
@@ -424,15 +424,15 @@ class ReflectiveInjector extends Injector {
424
424
  /**
425
425
  * 用于获取当前注入器上下文内的实例、对象或数据
426
426
  * @param token 访问 token
427
- * @param flags 查询规则
428
427
  * @param notFoundValue 如未查找到的返回值
428
+ * @param flags 查询规则
429
429
  */
430
- get(token, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
430
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
431
431
  var _a;
432
432
  flags = flags || InjectFlags.Default;
433
433
  if (flags === InjectFlags.SkipSelf) {
434
434
  if (this.parentInjector) {
435
- return this.parentInjector.get(token, InjectFlags.Default, notFoundValue);
435
+ return this.parentInjector.get(token, notFoundValue);
436
436
  }
437
437
  if (notFoundValue !== THROW_IF_NOT_FOUND) {
438
438
  return notFoundValue;
@@ -476,9 +476,12 @@ class ReflectiveInjector extends Injector {
476
476
  return notFoundValue;
477
477
  }
478
478
  if (this.parentInjector) {
479
- return this.parentInjector.get(token, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default, notFoundValue);
479
+ return this.parentInjector.get(token, notFoundValue, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default);
480
480
  }
481
481
  if (notFoundValue === THROW_IF_NOT_FOUND) {
482
+ // if (flags === InjectFlags.Optional) {
483
+ // return null as U
484
+ // }
482
485
  throw reflectiveInjectorErrorFn(token);
483
486
  }
484
487
  return notFoundValue;
@@ -508,11 +511,11 @@ class ReflectiveInjector extends Injector {
508
511
  const tryValue = {};
509
512
  const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
510
513
  if (dep.visibility instanceof Self) {
511
- reflectiveValue = this.get(injectToken, InjectFlags.Self, tryValue);
514
+ reflectiveValue = this.get(injectToken, tryValue, InjectFlags.Self);
512
515
  }
513
516
  else if (dep.visibility instanceof SkipSelf) {
514
517
  if (this.parentInjector) {
515
- reflectiveValue = this.parentInjector.get(injectToken, InjectFlags.Default, tryValue);
518
+ reflectiveValue = this.parentInjector.get(injectToken, tryValue);
516
519
  }
517
520
  else {
518
521
  if (dep.optional) {
@@ -525,7 +528,7 @@ class ReflectiveInjector extends Injector {
525
528
  }
526
529
  }
527
530
  else {
528
- reflectiveValue = this.get(injectToken, InjectFlags.Default, tryValue);
531
+ reflectiveValue = this.get(injectToken, tryValue);
529
532
  }
530
533
  if (reflectiveValue === tryValue) {
531
534
  if (dep.optional) {
@@ -843,7 +846,12 @@ class Component extends ReflectiveInjector {
843
846
  }
844
847
  }
845
848
  if (unmountedCallbacks.length) {
846
- this.unmountedCallbacks = unmountedCallbacks;
849
+ if (this.unmountedCallbacks) {
850
+ this.unmountedCallbacks.push(...unmountedCallbacks);
851
+ }
852
+ else {
853
+ this.unmountedCallbacks = unmountedCallbacks;
854
+ }
847
855
  }
848
856
  this.mountCallbacks = null;
849
857
  }
@@ -1232,9 +1240,9 @@ function withAnnotation(annotation, componentSetup) {
1232
1240
  /**
1233
1241
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
1234
1242
  */
1235
- function inject(token, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
1243
+ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1236
1244
  const component = getSetupContext();
1237
- return component.get(token, flags, notFoundValue);
1245
+ return component.get(token, notFoundValue, flags);
1238
1246
  }
1239
1247
  /**
1240
1248
  * 获取当前组件实例
@@ -1884,7 +1892,7 @@ function viewfly(config) {
1884
1892
  return destroyed ? null : root;
1885
1893
  };
1886
1894
  }), function () {
1887
- if (destroyed) {
1895
+ if (destroyed || !autoUpdate) {
1888
1896
  return;
1889
1897
  }
1890
1898
  nextTick(() => {
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,7 @@ 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
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
211
245
  if (notFoundValue === THROW_IF_NOT_FOUND) {
212
246
  throw nullInjectorErrorFn(token);
213
247
  }
@@ -215,40 +249,6 @@ class NullInjector extends Injector {
215
249
  }
216
250
  }
217
251
 
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
252
  /**
253
253
  * 标准化 provide,并返回统一数据结构
254
254
  * @param provider
@@ -426,15 +426,15 @@ class ReflectiveInjector extends Injector {
426
426
  /**
427
427
  * 用于获取当前注入器上下文内的实例、对象或数据
428
428
  * @param token 访问 token
429
- * @param flags 查询规则
430
429
  * @param notFoundValue 如未查找到的返回值
430
+ * @param flags 查询规则
431
431
  */
432
- get(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
432
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
433
433
  var _a;
434
434
  flags = flags || exports.InjectFlags.Default;
435
435
  if (flags === exports.InjectFlags.SkipSelf) {
436
436
  if (this.parentInjector) {
437
- return this.parentInjector.get(token, exports.InjectFlags.Default, notFoundValue);
437
+ return this.parentInjector.get(token, notFoundValue);
438
438
  }
439
439
  if (notFoundValue !== THROW_IF_NOT_FOUND) {
440
440
  return notFoundValue;
@@ -478,9 +478,12 @@ class ReflectiveInjector extends Injector {
478
478
  return notFoundValue;
479
479
  }
480
480
  if (this.parentInjector) {
481
- return this.parentInjector.get(token, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default, notFoundValue);
481
+ return this.parentInjector.get(token, notFoundValue, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default);
482
482
  }
483
483
  if (notFoundValue === THROW_IF_NOT_FOUND) {
484
+ // if (flags === InjectFlags.Optional) {
485
+ // return null as U
486
+ // }
484
487
  throw reflectiveInjectorErrorFn(token);
485
488
  }
486
489
  return notFoundValue;
@@ -510,11 +513,11 @@ class ReflectiveInjector extends Injector {
510
513
  const tryValue = {};
511
514
  const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
512
515
  if (dep.visibility instanceof Self) {
513
- reflectiveValue = this.get(injectToken, exports.InjectFlags.Self, tryValue);
516
+ reflectiveValue = this.get(injectToken, tryValue, exports.InjectFlags.Self);
514
517
  }
515
518
  else if (dep.visibility instanceof SkipSelf) {
516
519
  if (this.parentInjector) {
517
- reflectiveValue = this.parentInjector.get(injectToken, exports.InjectFlags.Default, tryValue);
520
+ reflectiveValue = this.parentInjector.get(injectToken, tryValue);
518
521
  }
519
522
  else {
520
523
  if (dep.optional) {
@@ -527,7 +530,7 @@ class ReflectiveInjector extends Injector {
527
530
  }
528
531
  }
529
532
  else {
530
- reflectiveValue = this.get(injectToken, exports.InjectFlags.Default, tryValue);
533
+ reflectiveValue = this.get(injectToken, tryValue);
531
534
  }
532
535
  if (reflectiveValue === tryValue) {
533
536
  if (dep.optional) {
@@ -845,7 +848,12 @@ class Component extends ReflectiveInjector {
845
848
  }
846
849
  }
847
850
  if (unmountedCallbacks.length) {
848
- this.unmountedCallbacks = unmountedCallbacks;
851
+ if (this.unmountedCallbacks) {
852
+ this.unmountedCallbacks.push(...unmountedCallbacks);
853
+ }
854
+ else {
855
+ this.unmountedCallbacks = unmountedCallbacks;
856
+ }
849
857
  }
850
858
  this.mountCallbacks = null;
851
859
  }
@@ -1234,9 +1242,9 @@ function withAnnotation(annotation, componentSetup) {
1234
1242
  /**
1235
1243
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
1236
1244
  */
1237
- function inject(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
1245
+ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1238
1246
  const component = getSetupContext();
1239
- return component.get(token, flags, notFoundValue);
1247
+ return component.get(token, notFoundValue, flags);
1240
1248
  }
1241
1249
  /**
1242
1250
  * 获取当前组件实例
@@ -1886,7 +1894,7 @@ function viewfly(config) {
1886
1894
  return destroyed ? null : root;
1887
1895
  };
1888
1896
  }), function () {
1889
- if (destroyed) {
1897
+ if (destroyed || !autoUpdate) {
1890
1898
  return;
1891
1899
  }
1892
1900
  nextTick(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.3",
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": "8a25e6e350ba9cade6036506e7fe2aba4e4396ac",
50
+ "gitHead": "ef47d49227def3f760cec535ba7867e0e624f339",
51
51
  "dependencies": {
52
52
  "reflect-metadata": "^0.1.13"
53
53
  }