@viewfly/core 0.6.3 → 1.0.0-alpha.0
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/bundles/di/injector.d.ts +1 -1
- package/bundles/di/metadata.d.ts +2 -2
- package/bundles/di/null-injector.d.ts +2 -2
- package/bundles/di/reflective-injector.d.ts +2 -2
- package/bundles/foundation/component.d.ts +20 -5
- package/bundles/foundation/types.d.ts +6 -1
- package/bundles/index.esm.js +46 -32
- package/bundles/index.js +46 -32
- package/jsx-runtime/index.d.ts +0 -11
- package/package.json +2 -2
package/bundles/di/injector.d.ts
CHANGED
|
@@ -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,
|
|
25
|
+
abstract get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
|
|
26
26
|
}
|
package/bundles/di/metadata.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractType, Type } from './type';
|
|
2
|
-
import { InjectFlags } from './injector';
|
|
2
|
+
import { ExtractValueType, InjectFlags } from './injector';
|
|
3
3
|
import { InjectionToken } from './injection-token';
|
|
4
4
|
import { ForwardRef } from './forward-ref';
|
|
5
5
|
export interface Inject {
|
|
@@ -37,7 +37,7 @@ export declare const Optional: OptionalDecorator;
|
|
|
37
37
|
export interface Prop {
|
|
38
38
|
}
|
|
39
39
|
export interface PropDecorator {
|
|
40
|
-
<T
|
|
40
|
+
<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token?: T | ForwardRef<ExtractValueType<T>>, flags?: InjectFlags, notFoundValue?: U): PropertyDecorator;
|
|
41
41
|
new (token: any): Prop;
|
|
42
42
|
}
|
|
43
43
|
export declare const Prop: PropDecorator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Injector } from './injector';
|
|
1
|
+
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, notFoundValue?: any): any;
|
|
5
|
+
get(token: any, flag?: InjectFlags, notFoundValue?: any): any;
|
|
6
6
|
}
|
|
@@ -17,10 +17,10 @@ export declare class ReflectiveInjector extends Injector {
|
|
|
17
17
|
/**
|
|
18
18
|
* 用于获取当前注入器上下文内的实例、对象或数据
|
|
19
19
|
* @param token 访问 token
|
|
20
|
-
* @param notFoundValue 如未查找到的返回值
|
|
21
20
|
* @param flags 查询规则
|
|
21
|
+
* @param notFoundValue 如未查找到的返回值
|
|
22
22
|
*/
|
|
23
|
-
get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T,
|
|
23
|
+
get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
|
|
24
24
|
private getValue;
|
|
25
25
|
/**
|
|
26
26
|
* 解决并获取依赖参数
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractType, InjectFlags, InjectionToken, Injector, Provider, ReflectiveInjector, Type } from '../di/_api';
|
|
1
|
+
import { AbstractType, ExtractValueType, InjectFlags, InjectionToken, Injector, Provider, ReflectiveInjector, Type } from '../di/_api';
|
|
2
2
|
import { Key, Props } from './jsx-element';
|
|
3
3
|
import { ComponentView } from './_utils';
|
|
4
4
|
/**
|
|
@@ -215,14 +215,29 @@ export declare function watch<T, T1, T2, T3, T4, T5, T6, T7>(deps: [Signal<T>, S
|
|
|
215
215
|
export declare function watch<T>(deps: () => T, callback: WatchCallback<T, T>): () => void;
|
|
216
216
|
export declare function watch<T = any>(deps: Signal<any>[], callback: WatchCallback<T[], T[]>): () => void;
|
|
217
217
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @param
|
|
218
|
+
* 给组件添加注解
|
|
219
|
+
* @param annotation
|
|
220
|
+
* @param componentSetup
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* export customScope = new Scope('scopeName')
|
|
224
|
+
* export const App = withAnnotation({
|
|
225
|
+
* scope: customScope,
|
|
226
|
+
* providers: [
|
|
227
|
+
* ExampleService
|
|
228
|
+
* ]
|
|
229
|
+
* }, function(props: Props) {
|
|
230
|
+
* return () => {
|
|
231
|
+
* return <div>...</div>
|
|
232
|
+
* }
|
|
233
|
+
* })
|
|
234
|
+
* ```
|
|
220
235
|
*/
|
|
221
|
-
export declare function
|
|
236
|
+
export declare function withAnnotation<T extends JSXInternal.ComponentSetup>(annotation: JSXInternal.ComponentAnnotation, componentSetup: T): T;
|
|
222
237
|
/**
|
|
223
238
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
224
239
|
*/
|
|
225
|
-
export declare function inject<T
|
|
240
|
+
export declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
|
|
226
241
|
/**
|
|
227
242
|
* 获取当前组件实例
|
|
228
243
|
*/
|
|
@@ -2,6 +2,7 @@ import { Key } from './jsx-element';
|
|
|
2
2
|
import { ExtractInstanceType, DynamicRef } from './component';
|
|
3
3
|
import { Scope } from '../di/injectable';
|
|
4
4
|
import { NativeNode } from './injection-tokens';
|
|
5
|
+
import { Provider } from '../di/provider';
|
|
5
6
|
export type ViewNode = JSXInternal.ViewNode;
|
|
6
7
|
declare global {
|
|
7
8
|
namespace JSXInternal {
|
|
@@ -12,9 +13,13 @@ declare global {
|
|
|
12
13
|
$useMemo?(currentProps: P, prevProps: P): boolean;
|
|
13
14
|
}
|
|
14
15
|
type ViewNode = Element | JSXInternal.ElementClass | string | number | boolean | null | undefined | Iterable<ViewNode>;
|
|
16
|
+
interface ComponentAnnotation {
|
|
17
|
+
scope?: Scope;
|
|
18
|
+
providers?: Provider[];
|
|
19
|
+
}
|
|
15
20
|
interface ComponentSetup<P = any> {
|
|
16
21
|
(props: P): (() => ViewNode) | ComponentInstance<P>;
|
|
17
|
-
|
|
22
|
+
annotation?: ComponentAnnotation;
|
|
18
23
|
}
|
|
19
24
|
type Element<P = any, C extends string | ComponentSetup<P> = string | ComponentSetup<P>> = C extends string ? IntrinsicElements[C] : (() => Element) | ComponentInstance<P>;
|
|
20
25
|
interface IntrinsicAttributes {
|
package/bundles/index.esm.js
CHANGED
|
@@ -205,7 +205,7 @@ class NullInjector extends Injector {
|
|
|
205
205
|
super(...arguments);
|
|
206
206
|
this.parentInjector = null;
|
|
207
207
|
}
|
|
208
|
-
get(token, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
208
|
+
get(token, flag, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
209
209
|
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
210
210
|
throw nullInjectorErrorFn(token);
|
|
211
211
|
}
|
|
@@ -239,10 +239,10 @@ const Optional = function OptionalDecorator() {
|
|
|
239
239
|
return makeParamDecorator(Optional, new Optional());
|
|
240
240
|
}
|
|
241
241
|
};
|
|
242
|
-
const Prop = function PropDecorator(token, notFoundValue = THROW_IF_NOT_FOUND
|
|
242
|
+
const Prop = function PropDecorator(token, flags, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
243
243
|
if (!(this instanceof Prop)) {
|
|
244
244
|
return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
|
|
245
|
-
instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token,
|
|
245
|
+
instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, flags, notFoundValue);
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
248
|
};
|
|
@@ -424,15 +424,15 @@ class ReflectiveInjector extends Injector {
|
|
|
424
424
|
/**
|
|
425
425
|
* 用于获取当前注入器上下文内的实例、对象或数据
|
|
426
426
|
* @param token 访问 token
|
|
427
|
-
* @param notFoundValue 如未查找到的返回值
|
|
428
427
|
* @param flags 查询规则
|
|
428
|
+
* @param notFoundValue 如未查找到的返回值
|
|
429
429
|
*/
|
|
430
|
-
get(token, notFoundValue = THROW_IF_NOT_FOUND
|
|
430
|
+
get(token, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
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, notFoundValue);
|
|
435
|
+
return this.parentInjector.get(token, InjectFlags.Default, notFoundValue);
|
|
436
436
|
}
|
|
437
437
|
if (notFoundValue !== THROW_IF_NOT_FOUND) {
|
|
438
438
|
return notFoundValue;
|
|
@@ -476,7 +476,7 @@ class ReflectiveInjector extends Injector {
|
|
|
476
476
|
return notFoundValue;
|
|
477
477
|
}
|
|
478
478
|
if (this.parentInjector) {
|
|
479
|
-
return this.parentInjector.get(token,
|
|
479
|
+
return this.parentInjector.get(token, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default, notFoundValue);
|
|
480
480
|
}
|
|
481
481
|
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
482
482
|
throw reflectiveInjectorErrorFn(token);
|
|
@@ -508,11 +508,11 @@ class ReflectiveInjector extends Injector {
|
|
|
508
508
|
const tryValue = {};
|
|
509
509
|
const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
|
|
510
510
|
if (dep.visibility instanceof Self) {
|
|
511
|
-
reflectiveValue = this.get(injectToken,
|
|
511
|
+
reflectiveValue = this.get(injectToken, InjectFlags.Self, tryValue);
|
|
512
512
|
}
|
|
513
513
|
else if (dep.visibility instanceof SkipSelf) {
|
|
514
514
|
if (this.parentInjector) {
|
|
515
|
-
reflectiveValue = this.parentInjector.get(injectToken, tryValue);
|
|
515
|
+
reflectiveValue = this.parentInjector.get(injectToken, InjectFlags.Default, tryValue);
|
|
516
516
|
}
|
|
517
517
|
else {
|
|
518
518
|
if (dep.optional) {
|
|
@@ -525,7 +525,7 @@ class ReflectiveInjector extends Injector {
|
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
527
|
else {
|
|
528
|
-
reflectiveValue = this.get(injectToken, tryValue);
|
|
528
|
+
reflectiveValue = this.get(injectToken, InjectFlags.Default, tryValue);
|
|
529
529
|
}
|
|
530
530
|
if (reflectiveValue === tryValue) {
|
|
531
531
|
if (dep.optional) {
|
|
@@ -656,7 +656,8 @@ class Component extends ReflectiveInjector {
|
|
|
656
656
|
return this._changed;
|
|
657
657
|
}
|
|
658
658
|
constructor(parentComponent, type, props, key) {
|
|
659
|
-
|
|
659
|
+
const annotation = type.annotation || {};
|
|
660
|
+
super(parentComponent, annotation.providers || [], annotation.scope);
|
|
660
661
|
this.parentComponent = parentComponent;
|
|
661
662
|
this.type = type;
|
|
662
663
|
this.props = props;
|
|
@@ -1199,19 +1200,37 @@ function watch(deps, callback) {
|
|
|
1199
1200
|
return destroyFn;
|
|
1200
1201
|
}
|
|
1201
1202
|
/**
|
|
1202
|
-
*
|
|
1203
|
-
* @param
|
|
1203
|
+
* 给组件添加注解
|
|
1204
|
+
* @param annotation
|
|
1205
|
+
* @param componentSetup
|
|
1206
|
+
* @example
|
|
1207
|
+
* ```ts
|
|
1208
|
+
* export customScope = new Scope('scopeName')
|
|
1209
|
+
* export const App = withAnnotation({
|
|
1210
|
+
* scope: customScope,
|
|
1211
|
+
* providers: [
|
|
1212
|
+
* ExampleService
|
|
1213
|
+
* ]
|
|
1214
|
+
* }, function(props: Props) {
|
|
1215
|
+
* return () => {
|
|
1216
|
+
* return <div>...</div>
|
|
1217
|
+
* }
|
|
1218
|
+
* })
|
|
1219
|
+
* ```
|
|
1204
1220
|
*/
|
|
1205
|
-
function
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1221
|
+
function withAnnotation(annotation, componentSetup) {
|
|
1222
|
+
const setup = function setup(props) {
|
|
1223
|
+
return componentSetup(props);
|
|
1224
|
+
};
|
|
1225
|
+
setup.annotation = annotation;
|
|
1226
|
+
return setup;
|
|
1208
1227
|
}
|
|
1209
1228
|
/**
|
|
1210
1229
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
1211
1230
|
*/
|
|
1212
|
-
function inject(token,
|
|
1231
|
+
function inject(token, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
1213
1232
|
const component = getSetupContext();
|
|
1214
|
-
return component.get(token,
|
|
1233
|
+
return component.get(token, flags, notFoundValue);
|
|
1215
1234
|
}
|
|
1216
1235
|
/**
|
|
1217
1236
|
* 获取当前组件实例
|
|
@@ -1848,19 +1867,19 @@ class RootComponent extends Component {
|
|
|
1848
1867
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1849
1868
|
function viewfly(config) {
|
|
1850
1869
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1851
|
-
const appProviders = [{
|
|
1852
|
-
provide: NativeRenderer,
|
|
1853
|
-
useValue: nativeRenderer
|
|
1854
|
-
}];
|
|
1855
1870
|
const modules = [];
|
|
1856
1871
|
let destroyed = false;
|
|
1857
1872
|
let appHost = null;
|
|
1858
|
-
const rootComponent = new RootComponent(context || null, (
|
|
1859
|
-
|
|
1873
|
+
const rootComponent = new RootComponent(context || null, withAnnotation({
|
|
1874
|
+
providers: [{
|
|
1875
|
+
provide: NativeRenderer,
|
|
1876
|
+
useValue: nativeRenderer
|
|
1877
|
+
}]
|
|
1878
|
+
}, () => {
|
|
1860
1879
|
return () => {
|
|
1861
1880
|
return destroyed ? null : root;
|
|
1862
1881
|
};
|
|
1863
|
-
}, function () {
|
|
1882
|
+
}), function () {
|
|
1864
1883
|
if (destroyed) {
|
|
1865
1884
|
return;
|
|
1866
1885
|
}
|
|
@@ -1882,12 +1901,7 @@ function viewfly(config) {
|
|
|
1882
1901
|
}
|
|
1883
1902
|
const app = {
|
|
1884
1903
|
provide(providers) {
|
|
1885
|
-
|
|
1886
|
-
appProviders.unshift(...providers);
|
|
1887
|
-
}
|
|
1888
|
-
else {
|
|
1889
|
-
appProviders.unshift(providers);
|
|
1890
|
-
}
|
|
1904
|
+
rootComponent.provide(providers);
|
|
1891
1905
|
return app;
|
|
1892
1906
|
},
|
|
1893
1907
|
use(module) {
|
|
@@ -1937,4 +1951,4 @@ function viewfly(config) {
|
|
|
1937
1951
|
return app;
|
|
1938
1952
|
}
|
|
1939
1953
|
|
|
1940
|
-
export { Component, DynamicRef, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, NativeRenderer, NullInjector, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, Type, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated,
|
|
1954
|
+
export { Component, DynamicRef, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, NativeRenderer, NullInjector, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, Type, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
|
package/bundles/index.js
CHANGED
|
@@ -207,7 +207,7 @@ class NullInjector extends Injector {
|
|
|
207
207
|
super(...arguments);
|
|
208
208
|
this.parentInjector = null;
|
|
209
209
|
}
|
|
210
|
-
get(token, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
210
|
+
get(token, flag, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
211
211
|
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
212
212
|
throw nullInjectorErrorFn(token);
|
|
213
213
|
}
|
|
@@ -241,10 +241,10 @@ const Optional = function OptionalDecorator() {
|
|
|
241
241
|
return makeParamDecorator(Optional, new Optional());
|
|
242
242
|
}
|
|
243
243
|
};
|
|
244
|
-
const Prop = function PropDecorator(token, notFoundValue = THROW_IF_NOT_FOUND
|
|
244
|
+
const Prop = function PropDecorator(token, flags, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
245
245
|
if (!(this instanceof Prop)) {
|
|
246
246
|
return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
|
|
247
|
-
instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token,
|
|
247
|
+
instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, flags, notFoundValue);
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
};
|
|
@@ -426,15 +426,15 @@ class ReflectiveInjector extends Injector {
|
|
|
426
426
|
/**
|
|
427
427
|
* 用于获取当前注入器上下文内的实例、对象或数据
|
|
428
428
|
* @param token 访问 token
|
|
429
|
-
* @param notFoundValue 如未查找到的返回值
|
|
430
429
|
* @param flags 查询规则
|
|
430
|
+
* @param notFoundValue 如未查找到的返回值
|
|
431
431
|
*/
|
|
432
|
-
get(token, notFoundValue = THROW_IF_NOT_FOUND
|
|
432
|
+
get(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
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, notFoundValue);
|
|
437
|
+
return this.parentInjector.get(token, exports.InjectFlags.Default, notFoundValue);
|
|
438
438
|
}
|
|
439
439
|
if (notFoundValue !== THROW_IF_NOT_FOUND) {
|
|
440
440
|
return notFoundValue;
|
|
@@ -478,7 +478,7 @@ class ReflectiveInjector extends Injector {
|
|
|
478
478
|
return notFoundValue;
|
|
479
479
|
}
|
|
480
480
|
if (this.parentInjector) {
|
|
481
|
-
return this.parentInjector.get(token,
|
|
481
|
+
return this.parentInjector.get(token, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default, notFoundValue);
|
|
482
482
|
}
|
|
483
483
|
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
484
484
|
throw reflectiveInjectorErrorFn(token);
|
|
@@ -510,11 +510,11 @@ class ReflectiveInjector extends Injector {
|
|
|
510
510
|
const tryValue = {};
|
|
511
511
|
const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
|
|
512
512
|
if (dep.visibility instanceof Self) {
|
|
513
|
-
reflectiveValue = this.get(injectToken,
|
|
513
|
+
reflectiveValue = this.get(injectToken, exports.InjectFlags.Self, tryValue);
|
|
514
514
|
}
|
|
515
515
|
else if (dep.visibility instanceof SkipSelf) {
|
|
516
516
|
if (this.parentInjector) {
|
|
517
|
-
reflectiveValue = this.parentInjector.get(injectToken, tryValue);
|
|
517
|
+
reflectiveValue = this.parentInjector.get(injectToken, exports.InjectFlags.Default, tryValue);
|
|
518
518
|
}
|
|
519
519
|
else {
|
|
520
520
|
if (dep.optional) {
|
|
@@ -527,7 +527,7 @@ class ReflectiveInjector extends Injector {
|
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
else {
|
|
530
|
-
reflectiveValue = this.get(injectToken, tryValue);
|
|
530
|
+
reflectiveValue = this.get(injectToken, exports.InjectFlags.Default, tryValue);
|
|
531
531
|
}
|
|
532
532
|
if (reflectiveValue === tryValue) {
|
|
533
533
|
if (dep.optional) {
|
|
@@ -658,7 +658,8 @@ class Component extends ReflectiveInjector {
|
|
|
658
658
|
return this._changed;
|
|
659
659
|
}
|
|
660
660
|
constructor(parentComponent, type, props, key) {
|
|
661
|
-
|
|
661
|
+
const annotation = type.annotation || {};
|
|
662
|
+
super(parentComponent, annotation.providers || [], annotation.scope);
|
|
662
663
|
this.parentComponent = parentComponent;
|
|
663
664
|
this.type = type;
|
|
664
665
|
this.props = props;
|
|
@@ -1201,19 +1202,37 @@ function watch(deps, callback) {
|
|
|
1201
1202
|
return destroyFn;
|
|
1202
1203
|
}
|
|
1203
1204
|
/**
|
|
1204
|
-
*
|
|
1205
|
-
* @param
|
|
1205
|
+
* 给组件添加注解
|
|
1206
|
+
* @param annotation
|
|
1207
|
+
* @param componentSetup
|
|
1208
|
+
* @example
|
|
1209
|
+
* ```ts
|
|
1210
|
+
* export customScope = new Scope('scopeName')
|
|
1211
|
+
* export const App = withAnnotation({
|
|
1212
|
+
* scope: customScope,
|
|
1213
|
+
* providers: [
|
|
1214
|
+
* ExampleService
|
|
1215
|
+
* ]
|
|
1216
|
+
* }, function(props: Props) {
|
|
1217
|
+
* return () => {
|
|
1218
|
+
* return <div>...</div>
|
|
1219
|
+
* }
|
|
1220
|
+
* })
|
|
1221
|
+
* ```
|
|
1206
1222
|
*/
|
|
1207
|
-
function
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1223
|
+
function withAnnotation(annotation, componentSetup) {
|
|
1224
|
+
const setup = function setup(props) {
|
|
1225
|
+
return componentSetup(props);
|
|
1226
|
+
};
|
|
1227
|
+
setup.annotation = annotation;
|
|
1228
|
+
return setup;
|
|
1210
1229
|
}
|
|
1211
1230
|
/**
|
|
1212
1231
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
1213
1232
|
*/
|
|
1214
|
-
function inject(token,
|
|
1233
|
+
function inject(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
1215
1234
|
const component = getSetupContext();
|
|
1216
|
-
return component.get(token,
|
|
1235
|
+
return component.get(token, flags, notFoundValue);
|
|
1217
1236
|
}
|
|
1218
1237
|
/**
|
|
1219
1238
|
* 获取当前组件实例
|
|
@@ -1850,19 +1869,19 @@ class RootComponent extends Component {
|
|
|
1850
1869
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1851
1870
|
function viewfly(config) {
|
|
1852
1871
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1853
|
-
const appProviders = [{
|
|
1854
|
-
provide: NativeRenderer,
|
|
1855
|
-
useValue: nativeRenderer
|
|
1856
|
-
}];
|
|
1857
1872
|
const modules = [];
|
|
1858
1873
|
let destroyed = false;
|
|
1859
1874
|
let appHost = null;
|
|
1860
|
-
const rootComponent = new RootComponent(context || null, (
|
|
1861
|
-
|
|
1875
|
+
const rootComponent = new RootComponent(context || null, withAnnotation({
|
|
1876
|
+
providers: [{
|
|
1877
|
+
provide: NativeRenderer,
|
|
1878
|
+
useValue: nativeRenderer
|
|
1879
|
+
}]
|
|
1880
|
+
}, () => {
|
|
1862
1881
|
return () => {
|
|
1863
1882
|
return destroyed ? null : root;
|
|
1864
1883
|
};
|
|
1865
|
-
}, function () {
|
|
1884
|
+
}), function () {
|
|
1866
1885
|
if (destroyed) {
|
|
1867
1886
|
return;
|
|
1868
1887
|
}
|
|
@@ -1884,12 +1903,7 @@ function viewfly(config) {
|
|
|
1884
1903
|
}
|
|
1885
1904
|
const app = {
|
|
1886
1905
|
provide(providers) {
|
|
1887
|
-
|
|
1888
|
-
appProviders.unshift(...providers);
|
|
1889
|
-
}
|
|
1890
|
-
else {
|
|
1891
|
-
appProviders.unshift(providers);
|
|
1892
|
-
}
|
|
1906
|
+
rootComponent.provide(providers);
|
|
1893
1907
|
return app;
|
|
1894
1908
|
},
|
|
1895
1909
|
use(module) {
|
|
@@ -1976,7 +1990,7 @@ exports.onMounted = onMounted;
|
|
|
1976
1990
|
exports.onPropsChanged = onPropsChanged;
|
|
1977
1991
|
exports.onUnmounted = onUnmounted;
|
|
1978
1992
|
exports.onUpdated = onUpdated;
|
|
1979
|
-
exports.provide = provide;
|
|
1980
1993
|
exports.viewfly = viewfly;
|
|
1981
1994
|
exports.watch = watch;
|
|
1995
|
+
exports.withAnnotation = withAnnotation;
|
|
1982
1996
|
exports.withMemo = withMemo;
|
package/jsx-runtime/index.d.ts
CHANGED
|
@@ -7,15 +7,4 @@ import { jsx, jsxs, Fragment } from '@viewfly/core';
|
|
|
7
7
|
declare const jsxDEV: typeof jsx;
|
|
8
8
|
export { jsx, jsxs, Fragment, jsxDEV };
|
|
9
9
|
export declare namespace JSX {
|
|
10
|
-
type Element = JSXInternal.Element;
|
|
11
|
-
interface ElementClass extends JSXInternal.ElementClass {
|
|
12
|
-
}
|
|
13
|
-
interface IntrinsicElements extends JSXInternal.IntrinsicElements {
|
|
14
|
-
}
|
|
15
|
-
interface IntrinsicAttributes extends JSXInternal.IntrinsicAttributes {
|
|
16
|
-
}
|
|
17
|
-
interface ElementChildrenAttribute extends JSXInternal.ElementChildrenAttribute {
|
|
18
|
-
}
|
|
19
|
-
interface IntrinsicClassAttributes<T> extends JSXInternal.IntrinsicClassAttributes<T> {
|
|
20
|
-
}
|
|
21
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
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": "
|
|
50
|
+
"gitHead": "49d0f91818ce7bf9474ae386d8eb52624b31dbde",
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"reflect-metadata": "^0.1.13"
|
|
53
53
|
}
|