@viewfly/core 2.0.0-alpha.0 → 2.0.0-alpha.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.
@@ -460,6 +460,11 @@ declare function createContext(providers: Provider[], scope?: Scope, parentInjec
460
460
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
461
461
  */
462
462
  declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
463
+ interface ComponentAnnotation {
464
+ scope?: Scope;
465
+ providers?: Provider[];
466
+ }
467
+ declare function withAnnotation<T extends ComponentSetup>(annotation: ComponentAnnotation, component: T): T;
463
468
 
464
469
  declare function withMemo<T extends Props = Props>(canUseMemo: ComponentInstance<T>['$useMemo'], render: () => JSXNode): ComponentInstance<T>;
465
470
 
@@ -573,4 +578,4 @@ interface Module {
573
578
  }
574
579
  declare function viewfly<T extends NativeNode>(config: Config): Application<T>;
575
580
 
576
- export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassNames, type ClassProvider, Component, type ComponentInstance, type ComponentSetup, type ComponentView, type Config, type ConstructorProvider, DynamicRef, type ElementNamespace, ElementNamespaceMap, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, JSX, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type PropsChangedCallback, type ProvideScope, type Provider, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, Type, type TypeProvider, type ValueProvider, type ViewFlyNode, type WatchCallback, computed, createContext, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withMemo };
581
+ export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassNames, type ClassProvider, Component, type ComponentAnnotation, type ComponentInstance, type ComponentSetup, type ComponentView, type Config, type ConstructorProvider, DynamicRef, type ElementNamespace, ElementNamespaceMap, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, JSX, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type PropsChangedCallback, type ProvideScope, type Provider, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, Type, type TypeProvider, type ValueProvider, type ViewFlyNode, type WatchCallback, computed, createContext, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
@@ -1231,8 +1231,7 @@ function getCurrentInstance() {
1231
1231
  }
1232
1232
 
1233
1233
  const injectMap = new WeakMap();
1234
- function getParentInjector(component) {
1235
- let start = component.parentComponent;
1234
+ function getInjector(start) {
1236
1235
  while (start) {
1237
1236
  const injector = injectMap.get(start);
1238
1237
  if (injector) {
@@ -1245,7 +1244,7 @@ function getParentInjector(component) {
1245
1244
  function createContext(providers, scope, parentInjector) {
1246
1245
  return function context(props) {
1247
1246
  const instance = getCurrentInstance();
1248
- const injector = new ReflectiveInjector(parentInjector || getParentInjector(instance), providers, scope);
1247
+ const injector = new ReflectiveInjector(parentInjector || getInjector(instance), providers, scope);
1249
1248
  injectMap.set(instance, injector);
1250
1249
  return () => {
1251
1250
  return props.children;
@@ -1257,9 +1256,18 @@ function createContext(providers, scope, parentInjector) {
1257
1256
  */
1258
1257
  function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1259
1258
  const component = getCurrentInstance();
1260
- const injector = getParentInjector(component);
1259
+ const injector = getInjector(component);
1261
1260
  return injector.get(token, notFoundValue, flags);
1262
1261
  }
1262
+ function withAnnotation(annotation, component) {
1263
+ return function (props) {
1264
+ const instance = getCurrentInstance();
1265
+ const parentInjector = injectMap.get(instance) || getInjector(instance.parentComponent);
1266
+ const injector = new ReflectiveInjector(parentInjector, annotation.providers || [], annotation.scope);
1267
+ injectMap.set(instance, injector);
1268
+ return component(props);
1269
+ };
1270
+ }
1263
1271
 
1264
1272
  class NativeRenderer {
1265
1273
  }
@@ -2077,4 +2085,4 @@ function viewfly(config) {
2077
2085
  return app;
2078
2086
  }
2079
2087
 
2080
- export { Component, DynamicRef, ElementNamespaceMap, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, NativeRenderer, NullInjector, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, Type, computed, createContext, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withMemo };
2088
+ export { Component, DynamicRef, ElementNamespaceMap, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, NativeRenderer, NullInjector, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, Type, computed, createContext, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
package/bundles/index.js CHANGED
@@ -1233,8 +1233,7 @@ function getCurrentInstance() {
1233
1233
  }
1234
1234
 
1235
1235
  const injectMap = new WeakMap();
1236
- function getParentInjector(component) {
1237
- let start = component.parentComponent;
1236
+ function getInjector(start) {
1238
1237
  while (start) {
1239
1238
  const injector = injectMap.get(start);
1240
1239
  if (injector) {
@@ -1247,7 +1246,7 @@ function getParentInjector(component) {
1247
1246
  function createContext(providers, scope, parentInjector) {
1248
1247
  return function context(props) {
1249
1248
  const instance = getCurrentInstance();
1250
- const injector = new ReflectiveInjector(parentInjector || getParentInjector(instance), providers, scope);
1249
+ const injector = new ReflectiveInjector(parentInjector || getInjector(instance), providers, scope);
1251
1250
  injectMap.set(instance, injector);
1252
1251
  return () => {
1253
1252
  return props.children;
@@ -1259,9 +1258,18 @@ function createContext(providers, scope, parentInjector) {
1259
1258
  */
1260
1259
  function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1261
1260
  const component = getCurrentInstance();
1262
- const injector = getParentInjector(component);
1261
+ const injector = getInjector(component);
1263
1262
  return injector.get(token, notFoundValue, flags);
1264
1263
  }
1264
+ function withAnnotation(annotation, component) {
1265
+ return function (props) {
1266
+ const instance = getCurrentInstance();
1267
+ const parentInjector = injectMap.get(instance) || getInjector(instance.parentComponent);
1268
+ const injector = new ReflectiveInjector(parentInjector, annotation.providers || [], annotation.scope);
1269
+ injectMap.set(instance, injector);
1270
+ return component(props);
1271
+ };
1272
+ }
1265
1273
 
1266
1274
  class NativeRenderer {
1267
1275
  }
@@ -2122,4 +2130,5 @@ exports.onUnmounted = onUnmounted;
2122
2130
  exports.onUpdated = onUpdated;
2123
2131
  exports.viewfly = viewfly;
2124
2132
  exports.watch = watch;
2133
+ exports.withAnnotation = withAnnotation;
2125
2134
  exports.withMemo = withMemo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.1",
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",
@@ -50,7 +50,7 @@
50
50
  "bugs": {
51
51
  "url": "https://github.com/viewfly/viewfly.git/issues"
52
52
  },
53
- "gitHead": "5fdcdcdca224d1eecdfd6a68abb1c3fb9c01d88a",
53
+ "gitHead": "7a4f48b8c21d4450ff837485c191e3d9bf88f5fb",
54
54
  "dependencies": {
55
55
  "reflect-metadata": "^0.2.2"
56
56
  }