@faasjs/react 0.0.5-beta.5 → 1.0.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/README.md CHANGED
@@ -10,7 +10,31 @@ React plugin for FaasJS.
10
10
 
11
11
  ## Install
12
12
 
13
- npm install @faasjs/react react react-dom
13
+ npm install @faasjs/react
14
+
15
+ ## Usage
16
+
17
+ 1. Initialize [FaasReactClient](#faasreactclient)
18
+
19
+ ```ts
20
+ import { FaasReactClient } from '@faasjs/react'
21
+
22
+ const client = FaasReactClient({
23
+ domain: 'localhost:8080/api'
24
+ })
25
+ ```
26
+ 2. Use [faas](#faas), [useFaas](#usefaas) or [FaasDataWrapper](#faasdatawrapper).
27
+
28
+ ## Usage with [@preact/signal-react](https://github.com/preactjs/signals/blob/main/packages/react/README.md)
29
+
30
+ 1. `npm i --save-dev @preact/signals-react-transform`
31
+ 2. Add `@preact/signals-react-transform` to babel config:
32
+ ```json
33
+ {
34
+ "plugins": [["module:@preact/signals-react-transform"]]
35
+ }
36
+ ```
37
+ 3. Add `import '@preact/signals-react/auto'` to your test files.
14
38
 
15
39
  ## Modules
16
40
 
@@ -257,7 +281,9 @@ A data wrapper for react components
257
281
 
258
282
  `JSX.Element`
259
283
 
260
- ```ts
284
+ **`Example`**
285
+
286
+ ```tsx
261
287
  <FaasDataWrapper<{
262
288
  id: string
263
289
  title: string
@@ -286,6 +312,8 @@ Before use faas, you should initialize a FaasReactClient.
286
312
 
287
313
  [`FaasReactClientInstance`](#faasreactclientinstance)
288
314
 
315
+ **`Example`**
316
+
289
317
  ```ts
290
318
  const client = FaasReactClient({
291
319
  domain: 'localhost:8080/api'
@@ -317,6 +345,8 @@ Request faas server
317
345
 
318
346
  `Promise`\<[`Response`](classes/Response.md)\<[`FaasData`](#faasdata)\<`PathOrData`\>\>\>
319
347
 
348
+ **`Example`**
349
+
320
350
  ```ts
321
351
  faas<{ title: string }>('post/get', { id: 1 }).then(res => {
322
352
  console.log(res.data.title)
@@ -341,6 +371,8 @@ Get FaasReactClient instance
341
371
 
342
372
  [`FaasReactClientInstance`](#faasreactclientinstance)
343
373
 
374
+ **`Example`**
375
+
344
376
  ```ts
345
377
  getClient()
346
378
  // or
@@ -408,7 +440,9 @@ Request faas server with React hook
408
440
 
409
441
  [`FaasDataInjection`](#faasdatainjection)\<[`FaasData`](#faasdata)\<`PathOrData`\>\>
410
442
 
411
- ```ts
443
+ **`Example`**
444
+
445
+ ```tsx
412
446
  function Post ({ id }) {
413
447
  const { data } = useFaas<{ title: string }>('post/get', { id })
414
448
  return <h1>{data.title}</h1>
package/dist/index.d.mts CHANGED
@@ -5,7 +5,8 @@ export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/brows
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { ReactNode, ReactElement, Component, SetStateAction } from 'react';
7
7
  import * as _preact_signals_core from '@preact/signals-core';
8
- export { batch, computed, effect, signal as originSignal, useSignal as originUseSignal, useComputed, useSignalEffect } from '@preact/signals-react';
8
+ export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
9
+ export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
9
10
 
10
11
  type FaasReactClientInstance = {
11
12
  id: string
@@ -78,6 +79,7 @@ type FaasReactClientOptions = {
78
79
  * @param props.options {Options} The options of client
79
80
  * @returns {FaasReactClientInstance}
80
81
  *
82
+ * @example
81
83
  * ```ts
82
84
  * const client = FaasReactClient({
83
85
  * domain: 'localhost:8080/api'
@@ -90,6 +92,7 @@ declare function FaasReactClient({ domain, options, onError, }: FaasReactClientO
90
92
  * @param domain {string} empty string for default domain
91
93
  * @returns {FaasReactClientInstance}
92
94
  *
95
+ * @example
93
96
  * ```ts
94
97
  * getClient()
95
98
  * // or
@@ -104,6 +107,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
104
107
  * @param params {object} action params
105
108
  * @returns {Promise<Response<any>>}
106
109
  *
110
+ * @example
107
111
  * ```ts
108
112
  * faas<{ title: string }>('post/get', { id: 1 }).then(res => {
109
113
  * console.log(res.data.title)
@@ -113,11 +117,13 @@ declare function getClient(domain?: string): FaasReactClientInstance;
113
117
  declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrData, params: FaasParams$1<PathOrData>): Promise<Response$1<FaasData$1<PathOrData>>>;
114
118
  /**
115
119
  * Request faas server with React hook
120
+ *
116
121
  * @param action {string} action name
117
122
  * @param defaultParams {object} initial action params
118
123
  * @returns {FaasDataInjection<any>}
119
124
  *
120
- * ```ts
125
+ * @example
126
+ * ```tsx
121
127
  * function Post ({ id }) {
122
128
  * const { data } = useFaas<{ title: string }>('post/get', { id })
123
129
  * return <h1>{data.title}</h1>
@@ -127,9 +133,11 @@ declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrDa
127
133
  declare function useFaas<PathOrData extends FaasAction$1>(action: string | PathOrData, defaultParams: FaasParams$1<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData$1<PathOrData>>;
128
134
  /**
129
135
  * A data wrapper for react components
136
+ *
130
137
  * @returns {JSX.Element}
131
138
  *
132
- * ```ts
139
+ * @example
140
+ * ```tsx
133
141
  * <FaasDataWrapper<{
134
142
  * id: string
135
143
  * title: string
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@ export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/brows
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { ReactNode, ReactElement, Component, SetStateAction } from 'react';
7
7
  import * as _preact_signals_core from '@preact/signals-core';
8
- export { batch, computed, effect, signal as originSignal, useSignal as originUseSignal, useComputed, useSignalEffect } from '@preact/signals-react';
8
+ export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
9
+ export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
9
10
 
10
11
  type FaasReactClientInstance = {
11
12
  id: string
@@ -78,6 +79,7 @@ type FaasReactClientOptions = {
78
79
  * @param props.options {Options} The options of client
79
80
  * @returns {FaasReactClientInstance}
80
81
  *
82
+ * @example
81
83
  * ```ts
82
84
  * const client = FaasReactClient({
83
85
  * domain: 'localhost:8080/api'
@@ -90,6 +92,7 @@ declare function FaasReactClient({ domain, options, onError, }: FaasReactClientO
90
92
  * @param domain {string} empty string for default domain
91
93
  * @returns {FaasReactClientInstance}
92
94
  *
95
+ * @example
93
96
  * ```ts
94
97
  * getClient()
95
98
  * // or
@@ -104,6 +107,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
104
107
  * @param params {object} action params
105
108
  * @returns {Promise<Response<any>>}
106
109
  *
110
+ * @example
107
111
  * ```ts
108
112
  * faas<{ title: string }>('post/get', { id: 1 }).then(res => {
109
113
  * console.log(res.data.title)
@@ -113,11 +117,13 @@ declare function getClient(domain?: string): FaasReactClientInstance;
113
117
  declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrData, params: FaasParams$1<PathOrData>): Promise<Response$1<FaasData$1<PathOrData>>>;
114
118
  /**
115
119
  * Request faas server with React hook
120
+ *
116
121
  * @param action {string} action name
117
122
  * @param defaultParams {object} initial action params
118
123
  * @returns {FaasDataInjection<any>}
119
124
  *
120
- * ```ts
125
+ * @example
126
+ * ```tsx
121
127
  * function Post ({ id }) {
122
128
  * const { data } = useFaas<{ title: string }>('post/get', { id })
123
129
  * return <h1>{data.title}</h1>
@@ -127,9 +133,11 @@ declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrDa
127
133
  declare function useFaas<PathOrData extends FaasAction$1>(action: string | PathOrData, defaultParams: FaasParams$1<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData$1<PathOrData>>;
128
134
  /**
129
135
  * A data wrapper for react components
136
+ *
130
137
  * @returns {JSX.Element}
131
138
  *
132
- * ```ts
139
+ * @example
140
+ * ```tsx
133
141
  * <FaasDataWrapper<{
134
142
  * id: string
135
143
  * title: string
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var react = require('react');
4
4
  var browser = require('@faasjs/browser');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var signalsReact = require('@preact/signals-react');
7
+ var runtime = require('@preact/signals-react/runtime');
7
8
 
8
9
  // src/client.tsx
9
10
  var clients = {};
@@ -220,9 +221,9 @@ function signal(initialValue, options = {}) {
220
221
  return state;
221
222
  }
222
223
  function useSignalState(initialValue, options = {}) {
223
- const state = signalsReact.useSignal(initialValue);
224
+ const state = runtime.useSignal(initialValue);
224
225
  if (options.debugName) {
225
- signalsReact.useSignalEffect(() => console.log(options.debugName, state.value));
226
+ runtime.useSignalEffect(() => console.log(options.debugName, state.value));
226
227
  }
227
228
  return [
228
229
  state.value,
@@ -250,15 +251,19 @@ Object.defineProperty(exports, "originSignal", {
250
251
  });
251
252
  Object.defineProperty(exports, "originUseSignal", {
252
253
  enumerable: true,
253
- get: function () { return signalsReact.useSignal; }
254
+ get: function () { return runtime.useSignal; }
254
255
  });
255
256
  Object.defineProperty(exports, "useComputed", {
256
257
  enumerable: true,
257
- get: function () { return signalsReact.useComputed; }
258
+ get: function () { return runtime.useComputed; }
258
259
  });
259
260
  Object.defineProperty(exports, "useSignalEffect", {
260
261
  enumerable: true,
261
- get: function () { return signalsReact.useSignalEffect; }
262
+ get: function () { return runtime.useSignalEffect; }
263
+ });
264
+ Object.defineProperty(exports, "useSignals", {
265
+ enumerable: true,
266
+ get: function () { return runtime.useSignals; }
262
267
  });
263
268
  exports.ErrorBoundary = ErrorBoundary;
264
269
  exports.FaasDataWrapper = FaasDataWrapper;
package/dist/index.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  import { useState, useEffect, cloneElement, Component } from 'react';
2
2
  import { FaasBrowserClient } from '@faasjs/browser';
3
3
  import { jsx, jsxs } from 'react/jsx-runtime';
4
- import { signal as signal$1, effect, useSignal, useSignalEffect } from '@preact/signals-react';
5
- export { batch, computed, effect, signal as originSignal, useSignal as originUseSignal, useComputed, useSignalEffect } from '@preact/signals-react';
4
+ import { signal as signal$1, effect } from '@preact/signals-react';
5
+ export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
6
+ import { useSignal, useSignalEffect } from '@preact/signals-react/runtime';
7
+ export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
6
8
 
7
9
  // src/client.tsx
8
10
  var clients = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "0.0.5-beta.5",
3
+ "version": "1.0.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@faasjs/browser": "0.0.5-beta.5"
25
+ "@faasjs/browser": "1.0.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "*",