@viewfly/core 0.2.5 → 0.3.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.
@@ -212,9 +212,13 @@ export declare function useEffect<T = any>(deps: Signal<any>[], effect: EffectCa
212
212
  * 通过 IoC 容器当前组件提供上下文共享数据的方法
213
213
  * @param provider
214
214
  */
215
- export declare function provide(provider: Provider | Provider[]): Component;
215
+ export declare function provide(provider: Provider | Provider[]): void;
216
216
  /**
217
217
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
218
218
  */
219
219
  export declare function inject<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
220
+ /**
221
+ * 获取当前组件实例
222
+ */
223
+ export declare function getCurrentInstance(): Component;
220
224
  export {};
@@ -1,5 +1,6 @@
1
1
  import { Key } from './jsx-element';
2
2
  import { ExtractInstanceType, Ref } from './component';
3
+ import { Scope } from '../di/injectable';
3
4
  export type JSXNode = JSXInternal.JSXNode;
4
5
  export declare namespace JSXInternal {
5
6
  type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
@@ -8,7 +9,10 @@ export declare namespace JSXInternal {
8
9
  $useMemo?(currentProps: P, prevProps: P): boolean;
9
10
  }
10
11
  type JSXNode = Element | JSXInternal.ElementClass | string | number | boolean | null | undefined | JSXNode[];
11
- type ComponentSetup<P = any> = (props: P) => (() => Element) | ComponentInstance<P>;
12
+ interface ComponentSetup<P = any> {
13
+ (props: P): (() => Element) | ComponentInstance<P>;
14
+ scope?: Scope;
15
+ }
12
16
  type Element<P = any, C extends string | ComponentSetup<P> = string | ComponentSetup<P>> = C extends string ? IntrinsicElements[C] : (() => Element) | ComponentInstance<P>;
13
17
  interface IntrinsicAttributes {
14
18
  key?: Key;
@@ -1,3 +1,5 @@
1
+ import 'reflect-metadata';
2
+
1
3
  class ForwardRef {
2
4
  constructor(forwardRefFn) {
3
5
  this.forwardRefFn = forwardRefFn;
@@ -657,7 +659,7 @@ class Component extends ReflectiveInjector {
657
659
  super(parentComponent, [{
658
660
  provide: Injector,
659
661
  useFactory: () => this
660
- }]);
662
+ }], type.scope);
661
663
  this.parentComponent = parentComponent;
662
664
  this.type = type;
663
665
  this.props = props;
@@ -1140,7 +1142,6 @@ function useEffect(deps, effect) {
1140
1142
  function provide(provider) {
1141
1143
  const component = getSetupContext();
1142
1144
  component.provide(provider);
1143
- return component;
1144
1145
  }
1145
1146
  /**
1146
1147
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
@@ -1149,6 +1150,12 @@ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags = InjectFlags.S
1149
1150
  const component = getSetupContext();
1150
1151
  return component.get(token, notFoundValue, flags);
1151
1152
  }
1153
+ /**
1154
+ * 获取当前组件实例
1155
+ */
1156
+ function getCurrentInstance() {
1157
+ return getSetupContext();
1158
+ }
1152
1159
 
1153
1160
  class NativeRenderer {
1154
1161
  }
@@ -1808,7 +1815,7 @@ class RootComponent extends Component {
1808
1815
  }
1809
1816
 
1810
1817
  const viewflyErrorFn = makeError('Viewfly');
1811
- const VERSION = "0.2.5";
1818
+ const VERSION = "0.3.1";
1812
1819
  function viewfly(config) {
1813
1820
  const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
1814
1821
  const appProviders = [];
@@ -1899,4 +1906,4 @@ function viewfly(config) {
1899
1906
  return app;
1900
1907
  }
1901
1908
 
1902
- export { Component, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXComponent, JSXElement, JSXText, NativeRenderer, NullInjector, Optional, Prop, Ref, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, THROW_IF_NOT_FOUND, Type, VERSION, createRenderer, forwardRef, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, provide, useDerived, useEffect, useRef, useSignal, viewfly, withMemo };
1909
+ export { Component, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXComponent, JSXElement, JSXText, NativeRenderer, NullInjector, Optional, Prop, Ref, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, THROW_IF_NOT_FOUND, Type, VERSION, createRenderer, forwardRef, getCurrentInstance, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, provide, useDerived, useEffect, useRef, useSignal, viewfly, withMemo };
package/bundles/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ require('reflect-metadata');
4
+
3
5
  class ForwardRef {
4
6
  constructor(forwardRefFn) {
5
7
  this.forwardRefFn = forwardRefFn;
@@ -659,7 +661,7 @@ class Component extends ReflectiveInjector {
659
661
  super(parentComponent, [{
660
662
  provide: Injector,
661
663
  useFactory: () => this
662
- }]);
664
+ }], type.scope);
663
665
  this.parentComponent = parentComponent;
664
666
  this.type = type;
665
667
  this.props = props;
@@ -1142,7 +1144,6 @@ function useEffect(deps, effect) {
1142
1144
  function provide(provider) {
1143
1145
  const component = getSetupContext();
1144
1146
  component.provide(provider);
1145
- return component;
1146
1147
  }
1147
1148
  /**
1148
1149
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
@@ -1151,6 +1152,12 @@ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags = exports.Injec
1151
1152
  const component = getSetupContext();
1152
1153
  return component.get(token, notFoundValue, flags);
1153
1154
  }
1155
+ /**
1156
+ * 获取当前组件实例
1157
+ */
1158
+ function getCurrentInstance() {
1159
+ return getSetupContext();
1160
+ }
1154
1161
 
1155
1162
  class NativeRenderer {
1156
1163
  }
@@ -1810,7 +1817,7 @@ class RootComponent extends Component {
1810
1817
  }
1811
1818
 
1812
1819
  const viewflyErrorFn = makeError('Viewfly');
1813
- const VERSION = "0.2.5";
1820
+ const VERSION = "0.3.1";
1814
1821
  function viewfly(config) {
1815
1822
  const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
1816
1823
  const appProviders = [];
@@ -1926,6 +1933,7 @@ exports.Type = Type;
1926
1933
  exports.VERSION = VERSION;
1927
1934
  exports.createRenderer = createRenderer;
1928
1935
  exports.forwardRef = forwardRef;
1936
+ exports.getCurrentInstance = getCurrentInstance;
1929
1937
  exports.inject = inject;
1930
1938
  exports.jsx = jsx;
1931
1939
  exports.jsxs = jsxs;
@@ -1,3 +1,4 @@
1
+ import 'reflect-metadata';
1
2
  export * from './di/_api';
2
3
  export * from './_utils/make-error';
3
4
  export * from './foundation/_api';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "0.2.5",
3
+ "version": "0.3.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",
@@ -47,5 +47,8 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/viewfly/viewfly.git/issues"
49
49
  },
50
- "gitHead": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94"
50
+ "gitHead": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94",
51
+ "dependencies": {
52
+ "reflect-metadata": "^0.1.13"
53
+ }
51
54
  }