@faasjs/react 0.0.2-beta.299 → 0.0.2-beta.307

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  React 插件
4
4
 
5
- [![License: MIT](https://img.shields.io/npm/l/@faasjs/react.svg)](https://github.com/faasjs/faasjs/blob/master/packages/faasjs/react/LICENSE)
5
+ [![License: MIT](https://img.shields.io/npm/l/@faasjs/react.svg)](https://github.com/faasjs/faasjs/blob/main/packages/faasjs/react/LICENSE)
6
6
  [![NPM Stable Version](https://img.shields.io/npm/v/@faasjs/react/stable.svg)](https://www.npmjs.com/package/@faasjs/react)
7
7
  [![NPM Beta Version](https://img.shields.io/npm/v/@faasjs/react/beta.svg)](https://www.npmjs.com/package/@faasjs/react)
8
8
 
package/lib/index.js CHANGED
@@ -6,7 +6,6 @@
6
6
 
7
7
  function FaasReactClient({ domain, options, onError }) {
8
8
  const client = new browser.FaasBrowserClient(domain, options);
9
- // async function faas<Path extends keyof FaasActions> (action: Path, params: FaasActions[Path]['request']): Promise<Response<FaasActions[Path]['response']>>
10
9
  async function faas(action, params) {
11
10
  if (onError)
12
11
  return client.action(action, params)
@@ -80,7 +79,7 @@
80
79
  if (!loaded && !request.loading)
81
80
  setLoaded(true);
82
81
  }, [request.loading]);
83
- react.useEffect(() => {
82
+ react.useEffect(function () {
84
83
  if (onDataChange)
85
84
  onDataChange(request);
86
85
  }, [JSON.stringify(request.data)]);
@@ -1,30 +1,31 @@
1
1
  /// <reference types="react" />
2
- import { Options, Params, Response, ResponseError } from '@faasjs/browser';
3
- export type { FaasBrowserClient, Options, Params, Response, ResponseHeaders, ResponseError } from '@faasjs/browser';
4
- declare type FaasDataInjection<T = any> = {
2
+ import { Options, Response, ResponseError } from '@faasjs/browser';
3
+ import { FaasAction, FaasData, FaasParams } from '@faasjs/types';
4
+ export type { FaasBrowserClient, Options, Response, ResponseHeaders, ResponseError } from '@faasjs/browser';
5
+ declare type FaasDataInjection<Data = any> = {
5
6
  loading: boolean;
6
- data: T;
7
+ data: Data;
7
8
  error: any;
8
- promise: Promise<Response<T>>;
9
- reload(params?: Params): Promise<Response<T>>;
10
- setData: React.Dispatch<React.SetStateAction<T>>;
9
+ promise: Promise<Response<Data>>;
10
+ reload(params?: Record<string, any>): Promise<Response<Data>>;
11
+ setData: React.Dispatch<React.SetStateAction<Data>>;
11
12
  setLoading: React.Dispatch<React.SetStateAction<boolean>>;
12
- setPromise: React.Dispatch<React.SetStateAction<Promise<Response<T>>>>;
13
+ setPromise: React.Dispatch<React.SetStateAction<Promise<Response<Data>>>>;
13
14
  setError: React.Dispatch<React.SetStateAction<any>>;
14
15
  };
15
- declare type FaasDataProps<T = any> = {
16
- element(args: FaasDataInjection<T>): JSX.Element;
16
+ declare type FaasDataProps<PathOrData extends FaasAction> = {
17
+ element(args: FaasDataInjection<FaasData<PathOrData>>): JSX.Element;
17
18
  fallback?: JSX.Element | false;
18
19
  action: string;
19
- params?: Params;
20
- onDataChange?(args: FaasDataInjection<T>): void;
20
+ params?: FaasParams<PathOrData>;
21
+ onDataChange?(args: FaasDataInjection<FaasData<PathOrData>>): void;
21
22
  };
22
23
  export declare function FaasReactClient({ domain, options, onError }: {
23
24
  domain: string;
24
25
  options?: Options;
25
- onError?: (action: string, params: Params) => (res: ResponseError) => Promise<void>;
26
+ onError?: (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
26
27
  }): {
27
- faas: <T = any>(action: string, params: Params) => Promise<Response<T>>;
28
- useFaas: <T_1 = any>(action: string, defaultParams: Params) => FaasDataInjection<T_1>;
29
- FaasData<T_2 = any>({ action, params, fallback, element, onDataChange }: FaasDataProps<T_2>): JSX.Element;
28
+ faas: <PathOrData extends FaasAction>(action: string | PathOrData, params: FaasParams<PathOrData>) => Promise<Response<FaasData<PathOrData>>>;
29
+ useFaas: <PathOrData extends FaasAction>(action: string | PathOrData, defaultParams: FaasParams<PathOrData>) => FaasDataInjection<FaasData<PathOrData>>;
30
+ FaasData<PathOrData extends FaasAction>(props: FaasDataProps<PathOrData>): JSX.Element;
30
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "0.0.2-beta.299",
3
+ "version": "0.0.2-beta.307",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/react/src/index.d.ts",
@@ -10,6 +10,10 @@
10
10
  "url": "git+https://github.com/faasjs/faasjs.git",
11
11
  "directory": "packages/react"
12
12
  },
13
+ "bugs": {
14
+ "url": "https://github.com/faasjs/faasjs/issues"
15
+ },
16
+ "funding": "https://github.com/sponsors/faasjs",
13
17
  "scripts": {
14
18
  "prepack": "rm -rf ./lib && rollup -c"
15
19
  },
@@ -27,5 +31,8 @@
27
31
  "rollup-plugin-typescript2": "*",
28
32
  "typescript": "*"
29
33
  },
30
- "gitHead": "e59f67b45534eb87764e6419fbfbbb0d24e3271d"
34
+ "engines": {
35
+ "npm": ">=8.0.0"
36
+ },
37
+ "gitHead": "4ef3afa9950bed235fdf2a13ce7f79298c308055"
31
38
  }