@faasjs/react 0.0.5-beta.1 → 0.0.5-beta.2

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/dist/index.d.mts CHANGED
@@ -3,9 +3,9 @@ export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
3
3
  import { Options, ResponseError, Response as Response$1 } from '@faasjs/browser';
4
4
  export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import { ReactNode, ReactElement, Component } from 'react';
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, useComputed, useSignal, useSignalEffect } from '@preact/signals-react';
8
+ export { batch, computed, effect, signal as originSignal, useSignal as originUseSignal, useComputed, useSignalEffect } from '@preact/signals-react';
9
9
 
10
10
  type FaasReactClientInstance = {
11
11
  id: string
@@ -184,5 +184,24 @@ type SignalOptions = {
184
184
  * ```
185
185
  */
186
186
  declare function signal<T = any>(initialValue: any, options?: SignalOptions): _preact_signals_core.Signal<T>;
187
+ /**
188
+ * Create a [signal](https://preactjs.com/guide/v10/signals) like useState.
189
+ *
190
+ * ```tsx
191
+ * import { useSignalState, useSignalEffect } from '@faasjs/react'
192
+ *
193
+ * function App () {
194
+ * const [count, setCount] = useSignalState(0, { debugName: 'count' })
195
+ *
196
+ * useSignalEffect(() => console.log('count', count))
197
+ *
198
+ * return <div>
199
+ * <button onClick={() => setCount(count + 1)}>+</button>
200
+ * <span>{count}</span>
201
+ * </div>
202
+ * }
203
+ * ```
204
+ */
205
+ declare function useSignalState<T = any>(initialValue: T, options?: SignalOptions): readonly [T, (changes: SetStateAction<T>) => void];
187
206
 
188
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions };
207
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions, useSignalState };
package/dist/index.d.ts CHANGED
@@ -3,9 +3,9 @@ export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
3
3
  import { Options, ResponseError, Response as Response$1 } from '@faasjs/browser';
4
4
  export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import { ReactNode, ReactElement, Component } from 'react';
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, useComputed, useSignal, useSignalEffect } from '@preact/signals-react';
8
+ export { batch, computed, effect, signal as originSignal, useSignal as originUseSignal, useComputed, useSignalEffect } from '@preact/signals-react';
9
9
 
10
10
  type FaasReactClientInstance = {
11
11
  id: string
@@ -184,5 +184,24 @@ type SignalOptions = {
184
184
  * ```
185
185
  */
186
186
  declare function signal<T = any>(initialValue: any, options?: SignalOptions): _preact_signals_core.Signal<T>;
187
+ /**
188
+ * Create a [signal](https://preactjs.com/guide/v10/signals) like useState.
189
+ *
190
+ * ```tsx
191
+ * import { useSignalState, useSignalEffect } from '@faasjs/react'
192
+ *
193
+ * function App () {
194
+ * const [count, setCount] = useSignalState(0, { debugName: 'count' })
195
+ *
196
+ * useSignalEffect(() => console.log('count', count))
197
+ *
198
+ * return <div>
199
+ * <button onClick={() => setCount(count + 1)}>+</button>
200
+ * <span>{count}</span>
201
+ * </div>
202
+ * }
203
+ * ```
204
+ */
205
+ declare function useSignalState<T = any>(initialValue: T, options?: SignalOptions): readonly [T, (changes: SetStateAction<T>) => void];
187
206
 
188
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions };
207
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions, useSignalState };
package/dist/index.js CHANGED
@@ -219,6 +219,18 @@ function signal(initialValue, options = {}) {
219
219
  signalsReact.effect(() => console.debug(options.debugName, state.value));
220
220
  return state;
221
221
  }
222
+ function useSignalState(initialValue, options = {}) {
223
+ const state = signalsReact.useSignal(initialValue);
224
+ if (options.debugName) {
225
+ signalsReact.useSignalEffect(() => console.log(options.debugName, state.value));
226
+ }
227
+ return [
228
+ state.value,
229
+ (changes) => {
230
+ state.value = typeof changes === "function" ? changes(state.value) : changes;
231
+ }
232
+ ];
233
+ }
222
234
 
223
235
  Object.defineProperty(exports, 'batch', {
224
236
  enumerable: true,
@@ -236,13 +248,13 @@ Object.defineProperty(exports, 'originSignal', {
236
248
  enumerable: true,
237
249
  get: function () { return signalsReact.signal; }
238
250
  });
239
- Object.defineProperty(exports, 'useComputed', {
251
+ Object.defineProperty(exports, 'originUseSignal', {
240
252
  enumerable: true,
241
- get: function () { return signalsReact.useComputed; }
253
+ get: function () { return signalsReact.useSignal; }
242
254
  });
243
- Object.defineProperty(exports, 'useSignal', {
255
+ Object.defineProperty(exports, 'useComputed', {
244
256
  enumerable: true,
245
- get: function () { return signalsReact.useSignal; }
257
+ get: function () { return signalsReact.useComputed; }
246
258
  });
247
259
  Object.defineProperty(exports, 'useSignalEffect', {
248
260
  enumerable: true,
@@ -255,3 +267,4 @@ exports.faas = faas;
255
267
  exports.getClient = getClient;
256
268
  exports.signal = signal;
257
269
  exports.useFaas = useFaas;
270
+ exports.useSignalState = useSignalState;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
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 } from '@preact/signals-react';
5
- export { batch, computed, effect, signal as originSignal, useComputed, useSignal, useSignalEffect } from '@preact/signals-react';
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';
6
6
 
7
7
  // src/client.tsx
8
8
  var clients = {};
@@ -218,5 +218,17 @@ function signal(initialValue, options = {}) {
218
218
  effect(() => console.debug(options.debugName, state.value));
219
219
  return state;
220
220
  }
221
+ function useSignalState(initialValue, options = {}) {
222
+ const state = useSignal(initialValue);
223
+ if (options.debugName) {
224
+ useSignalEffect(() => console.log(options.debugName, state.value));
225
+ }
226
+ return [
227
+ state.value,
228
+ (changes) => {
229
+ state.value = typeof changes === "function" ? changes(state.value) : changes;
230
+ }
231
+ ];
232
+ }
221
233
 
222
- export { ErrorBoundary, FaasDataWrapper, FaasReactClient, faas, getClient, signal, useFaas };
234
+ export { ErrorBoundary, FaasDataWrapper, FaasReactClient, faas, getClient, signal, useFaas, useSignalState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "0.0.5-beta.1",
3
+ "version": "0.0.5-beta.2",
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.1"
25
+ "@faasjs/browser": "0.0.5-beta.2"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "*",