@faasjs/react 0.0.5-beta.4 → 0.0.5-beta.6

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`
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
 
@@ -47,6 +71,7 @@ React plugin for FaasJS.
47
71
  - [getClient](#getclient)
48
72
  - [signal](#signal)
49
73
  - [useFaas](#usefaas)
74
+ - [useSignalState](#usesignalstate)
50
75
 
51
76
  ## Type Aliases
52
77
 
@@ -256,7 +281,9 @@ A data wrapper for react components
256
281
 
257
282
  `JSX.Element`
258
283
 
259
- ```ts
284
+ **`Example`**
285
+
286
+ ```tsx
260
287
  <FaasDataWrapper<{
261
288
  id: string
262
289
  title: string
@@ -285,6 +312,8 @@ Before use faas, you should initialize a FaasReactClient.
285
312
 
286
313
  [`FaasReactClientInstance`](#faasreactclientinstance)
287
314
 
315
+ **`Example`**
316
+
288
317
  ```ts
289
318
  const client = FaasReactClient({
290
319
  domain: 'localhost:8080/api'
@@ -316,6 +345,8 @@ Request faas server
316
345
 
317
346
  `Promise`\<[`Response`](classes/Response.md)\<[`FaasData`](#faasdata)\<`PathOrData`\>\>\>
318
347
 
348
+ **`Example`**
349
+
319
350
  ```ts
320
351
  faas<{ title: string }>('post/get', { id: 1 }).then(res => {
321
352
  console.log(res.data.title)
@@ -340,6 +371,8 @@ Get FaasReactClient instance
340
371
 
341
372
  [`FaasReactClientInstance`](#faasreactclientinstance)
342
373
 
374
+ **`Example`**
375
+
343
376
  ```ts
344
377
  getClient()
345
378
  // or
@@ -407,9 +440,51 @@ Request faas server with React hook
407
440
 
408
441
  [`FaasDataInjection`](#faasdatainjection)\<[`FaasData`](#faasdata)\<`PathOrData`\>\>
409
442
 
410
- ```ts
443
+ **`Example`**
444
+
445
+ ```tsx
411
446
  function Post ({ id }) {
412
447
  const { data } = useFaas<{ title: string }>('post/get', { id })
413
448
  return <h1>{data.title}</h1>
414
449
  }
415
450
  ```
451
+
452
+ ___
453
+
454
+ ### useSignalState
455
+
456
+ ▸ **useSignalState**\<`T`\>(`initialValue`, `options?`): readonly [`T`, (`changes`: `SetStateAction`\<`T`\>) => `void`]
457
+
458
+ Create a [signal](https://preactjs.com/guide/v10/signals) like useState.
459
+
460
+ ```tsx
461
+ import { useSignalState, useSignalEffect } from '@faasjs/react'
462
+
463
+ function App () {
464
+ const [count, setCount] = useSignalState(0, { debugName: 'count' })
465
+
466
+ useSignalEffect(() => console.log('count', count))
467
+
468
+ return <div>
469
+ <button onClick={() => setCount(count + 1)}>+</button>
470
+ <span>{count}</span>
471
+ </div>
472
+ }
473
+ ```
474
+
475
+ #### Type parameters
476
+
477
+ | Name | Type |
478
+ | :------ | :------ |
479
+ | `T` | `any` |
480
+
481
+ #### Parameters
482
+
483
+ | Name | Type |
484
+ | :------ | :------ |
485
+ | `initialValue` | `T` |
486
+ | `options` | [`SignalOptions`](#signaloptions) |
487
+
488
+ #### Returns
489
+
490
+ readonly [`T`, (`changes`: `SetStateAction`\<`T`\>) => `void`]
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 } 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 } 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,15 @@ 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; }
262
263
  });
263
264
  exports.ErrorBoundary = ErrorBoundary;
264
265
  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 } 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.4",
3
+ "version": "0.0.5-beta.6",
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.4"
25
+ "@faasjs/browser": "0.0.5-beta.6"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "*",