use-effect-ts 0.0.6 → 0.0.8

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.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { useComponentLifecycle } from "./use-component-lifecycle.js";
2
- export { useRunEffect } from "./use-run-effect.js";
3
- export { useRunEffectLatest } from "./use-run-effect-latest.js";
4
- export { useRunEffectQueue } from "./use-run-effect-queue.js";
5
- export { useComponentScope } from "./use-component-scope.js";
6
- export { useLiveRef } from "./use-live-ref.js";
1
+ export { useComponentLifecycle } from './use-component-lifecycle.js';
2
+ export { useComponentScope } from './use-component-scope.js';
3
+ export { useLiveRef } from './use-live-ref.js';
4
+ export { useRunEffectLatest } from './use-run-effect-latest.js';
5
+ export { useRunEffectQueue } from './use-run-effect-queue.js';
6
+ export { useRunEffect } from './use-run-effect.js';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export { useComponentLifecycle } from "./use-component-lifecycle.js";
2
- export { useRunEffect } from "./use-run-effect.js";
3
- export { useRunEffectLatest } from "./use-run-effect-latest.js";
4
- export { useRunEffectQueue } from "./use-run-effect-queue.js";
5
- export { useComponentScope } from "./use-component-scope.js";
6
- export { useLiveRef } from "./use-live-ref.js";
1
+ export { useComponentLifecycle } from './use-component-lifecycle.js';
2
+ export { useComponentScope } from './use-component-scope.js';
3
+ export { useLiveRef } from './use-live-ref.js';
4
+ export { useRunEffectLatest } from './use-run-effect-latest.js';
5
+ export { useRunEffectQueue } from './use-run-effect-queue.js';
6
+ export { useRunEffect } from './use-run-effect.js';
@@ -1,5 +1,5 @@
1
- import { Effect, Scope } from "effect";
2
- export declare function useComponentLifecycle(effect: Effect.Effect<unknown, unknown, Scope.Scope>, { deps, }?: {
1
+ import { Effect, Scope } from 'effect';
2
+ export declare function useComponentLifecycle<A, E>(effect: Effect.Effect<A, E, Scope.Scope>, { deps, }?: {
3
3
  deps?: unknown[];
4
4
  }): void;
5
5
  //# sourceMappingURL=use-component-lifecycle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-component-lifecycle.d.ts","sourceRoot":"","sources":["../src/use-component-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI9C,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,EACpD,EACE,IAAS,GACV,GAAE;IACD,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;CACb,QAkBP"}
1
+ {"version":3,"file":"use-component-lifecycle.d.ts","sourceRoot":"","sources":["../src/use-component-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI9C,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,CAAC,EACxC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EACxC,EACE,IAAS,GACV,GAAE;IACD,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;CACb,QAuBP"}
@@ -1,6 +1,6 @@
1
- import { Effect, Fiber, Scope } from "effect";
2
- import { useEffect } from "react";
3
- import { useLiveRef } from "./use-live-ref.js";
1
+ import { Effect, Fiber, Scope } from 'effect';
2
+ import { useEffect } from 'react';
3
+ import { useLiveRef } from './use-live-ref.js';
4
4
  export function useComponentLifecycle(effect, { deps = [], } = {}) {
5
5
  const effectRef = useLiveRef(effect);
6
6
  useEffect(() => {
@@ -11,7 +11,8 @@ export function useComponentLifecycle(effect, { deps = [], } = {}) {
11
11
  const exit = yield* Fiber.interrupt(fiber);
12
12
  yield* Scope.close(scope, exit);
13
13
  }));
14
- void Effect.runPromise(Fiber.interrupt(fiber));
14
+ void Effect.runPromise(Fiber.interrupt(fiber).pipe(Effect.onInterrupt(() => Effect.logDebug('Fiber interrupted'))));
15
15
  };
16
+ // eslint-disable-next-line react-hooks/exhaustive-deps
16
17
  }, [effectRef, ...deps]);
17
18
  }
@@ -1,3 +1,3 @@
1
- import { Scope } from "effect";
1
+ import { Scope } from 'effect';
2
2
  export declare function useComponentScope(setup?: (scope: Scope.CloseableScope) => void): Scope.CloseableScope | undefined;
3
3
  //# sourceMappingURL=use-component-scope.d.ts.map
@@ -1,5 +1,5 @@
1
- import { Effect, Exit, Scope } from "effect";
2
- import { useEffect, useState } from "react";
1
+ import { Effect, Exit, Scope } from 'effect';
2
+ import { useEffect, useState } from 'react';
3
3
  export function useComponentScope(setup) {
4
4
  const [scope, setScope] = useState();
5
5
  useEffect(() => {
@@ -1,4 +1,4 @@
1
- import { useRef } from "react";
1
+ import { useRef } from 'react';
2
2
  export function useLiveRef(value) {
3
3
  const ref = useRef(value);
4
4
  ref.current = value;
@@ -1,3 +1,3 @@
1
- import { Effect } from "effect";
1
+ import { Effect } from 'effect';
2
2
  export declare function useRunEffectLatest<Args extends any[], A, E>(fn: (...args: Args) => Effect.Effect<A, E, never>): (...args: Args) => Promise<import("effect/Exit").Exit<import("effect/Fiber").RuntimeFiber<A, E>, never>>;
3
3
  //# sourceMappingURL=use-run-effect-latest.d.ts.map
@@ -1,6 +1,6 @@
1
- import { Effect, FiberHandle, Scope } from "effect";
2
- import { useComponentScope } from "./use-component-scope.js";
3
- import { useState } from "react";
1
+ import { Effect, FiberHandle, Scope } from 'effect';
2
+ import { useState } from 'react';
3
+ import { useComponentScope } from './use-component-scope.js';
4
4
  export function useRunEffectLatest(fn) {
5
5
  const [fiberHandle, setFiberHandle] = useState(null);
6
6
  useComponentScope((scope) => {
@@ -9,7 +9,7 @@ export function useRunEffectLatest(fn) {
9
9
  });
10
10
  return (...args) => {
11
11
  if (!fiberHandle) {
12
- throw new Error("useRunEffectLatest: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.");
12
+ throw new Error('useRunEffectLatest: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.');
13
13
  }
14
14
  return Effect.runPromiseExit(FiberHandle.run(fiberHandle, fn(...args)));
15
15
  };
@@ -1,3 +1,3 @@
1
- import { Effect } from "effect";
1
+ import { Effect } from 'effect';
2
2
  export declare function useRunEffectQueue<Args extends any[], A, E>(fn: (...args: Args) => Effect.Effect<A, E, never>): (...args: Args) => void;
3
3
  //# sourceMappingURL=use-run-effect-queue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-run-effect-queue.d.ts","sourceRoot":"","sources":["../src/use-run-effect-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA6B,MAAM,QAAQ,CAAC;AAI3D,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EACxD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,IA8BzC,GAAG,MAAM,IAAI,UAItB"}
1
+ {"version":3,"file":"use-run-effect-queue.d.ts","sourceRoot":"","sources":["../src/use-run-effect-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA6B,MAAM,QAAQ,CAAC;AAI3D,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EACxD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,IA+BzC,GAAG,MAAM,IAAI,UAItB"}
@@ -1,6 +1,6 @@
1
- import { Effect, Fiber, FiberHandle, Scope } from "effect";
2
- import { useComponentScope } from "./use-component-scope.js";
3
- import { useEffect, useRef } from "react";
1
+ import { Effect, Fiber, FiberHandle, Scope } from 'effect';
2
+ import { useEffect, useRef } from 'react';
3
+ import { useComponentScope } from './use-component-scope.js';
4
4
  export function useRunEffectQueue(fn) {
5
5
  const queue = useRef([]);
6
6
  const scope = useComponentScope();
@@ -21,6 +21,7 @@ export function useRunEffectQueue(fn) {
21
21
  runFromQueue();
22
22
  });
23
23
  };
24
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
25
  useEffect(runFromQueue, [scope]);
25
26
  return (...args) => {
26
27
  queue.current.push(args);
@@ -1,3 +1,3 @@
1
- import { Effect } from "effect";
1
+ import { Effect } from 'effect';
2
2
  export declare function useRunEffect<Args extends any[], A, E>(fn: (...args: Args) => Effect.Effect<A, E, never>): (...args: Args) => Promise<import("effect/Exit").Exit<import("effect/Fiber").RuntimeFiber<A, E>, never>>;
3
3
  //# sourceMappingURL=use-run-effect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-run-effect.d.ts","sourceRoot":"","sources":["../src/use-run-effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,QAAQ,CAAC;AAIjD,wBAAgB,YAAY,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EACnD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,IAQzC,GAAG,MAAM,IAAI,2FAStB"}
1
+ {"version":3,"file":"use-run-effect.d.ts","sourceRoot":"","sources":["../src/use-run-effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,QAAQ,CAAC;AAIjD,wBAAgB,YAAY,CAAC,IAAI,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EACnD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,IAQzC,GAAG,MAAM,IAAI,2FAYtB"}
@@ -1,6 +1,6 @@
1
- import { Effect, FiberSet, Scope } from "effect";
2
- import { useComponentScope } from "./use-component-scope.js";
3
- import { useState } from "react";
1
+ import { Effect, FiberSet, Scope } from 'effect';
2
+ import { useState } from 'react';
3
+ import { useComponentScope } from './use-component-scope.js';
4
4
  export function useRunEffect(fn) {
5
5
  const [fiberSet, setFiberSet] = useState(null);
6
6
  useComponentScope((scope) => {
@@ -9,7 +9,8 @@ export function useRunEffect(fn) {
9
9
  });
10
10
  return (...args) => {
11
11
  if (!fiberSet) {
12
- throw new Error("useRunEffect: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.");
12
+ console.error('useRunEffect: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.');
13
+ throw new Error('useRunEffect: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.');
13
14
  }
14
15
  return Effect.runPromiseExit(FiberSet.run(fiberSet, fn(...args)));
15
16
  };
package/package.json CHANGED
@@ -1,33 +1,35 @@
1
1
  {
2
2
  "name": "use-effect-ts",
3
- "type": "module",
4
- "version": "0.0.6",
5
- "exports": {
6
- ".": "./dist/index.js",
7
- "./*": "./dist/*"
3
+ "version": "0.0.8",
4
+ "private": false,
5
+ "repository": "pkishorez/monorepo",
6
+ "devDependencies": {
7
+ "@types/react": "19.2.7",
8
+ "effect": "3.19.14",
9
+ "typescript": "5.9.3",
10
+ "@monorepo/config": "1.0.0"
8
11
  },
9
- "scripts": {
10
- "build": "tsc",
11
- "lint": "tsc --noEmit",
12
- "dev": "tsc --watch",
13
- "updates": "npx -y npm-check-updates -u"
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.js",
15
+ "import": "./dist/index.js",
16
+ "default": "./dist/index.js"
17
+ }
14
18
  },
15
19
  "files": [
16
- "dist/",
17
- "src/",
20
+ "LICENCE",
18
21
  "README.md",
19
- "LICENCE"
22
+ "dist/",
23
+ "src/"
20
24
  ],
21
- "devDependencies": {
22
- "@tsconfig/node22": "22.0.2",
23
- "@types/react": "^19.1.9",
24
- "effect": "3.17.4",
25
- "react": "19.1.1",
26
- "typescript": "5.9.2"
27
- },
28
25
  "peerDependencies": {
29
- "effect": ">=3.0.0",
30
- "react": ">=18.0.0"
26
+ "effect": ">=3.19.14",
27
+ "react": ">=19.2.3"
31
28
  },
32
- "packageManager": "pnpm@10.14.0"
33
- }
29
+ "type": "module",
30
+ "scripts": {
31
+ "build": "tsc",
32
+ "dev": "tsc --watch",
33
+ "lint": "tsc --noEmit"
34
+ }
35
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { useComponentLifecycle } from "./use-component-lifecycle.js";
2
- export { useRunEffect } from "./use-run-effect.js";
3
- export { useRunEffectLatest } from "./use-run-effect-latest.js";
4
- export { useRunEffectQueue } from "./use-run-effect-queue.js";
5
- export { useComponentScope } from "./use-component-scope.js";
6
- export { useLiveRef } from "./use-live-ref.js";
1
+ export { useComponentLifecycle } from './use-component-lifecycle.js';
2
+ export { useComponentScope } from './use-component-scope.js';
3
+ export { useLiveRef } from './use-live-ref.js';
4
+ export { useRunEffectLatest } from './use-run-effect-latest.js';
5
+ export { useRunEffectQueue } from './use-run-effect-queue.js';
6
+ export { useRunEffect } from './use-run-effect.js';
@@ -1,9 +1,9 @@
1
- import { Effect, Fiber, Scope } from "effect";
2
- import { useEffect } from "react";
3
- import { useLiveRef } from "./use-live-ref.js";
1
+ import { Effect, Fiber, Scope } from 'effect';
2
+ import { useEffect } from 'react';
3
+ import { useLiveRef } from './use-live-ref.js';
4
4
 
5
- export function useComponentLifecycle(
6
- effect: Effect.Effect<unknown, unknown, Scope.Scope>,
5
+ export function useComponentLifecycle<A, E>(
6
+ effect: Effect.Effect<A, E, Scope.Scope>,
7
7
  {
8
8
  deps = [],
9
9
  }: {
@@ -23,7 +23,12 @@ export function useComponentLifecycle(
23
23
  yield* Scope.close(scope, exit);
24
24
  }),
25
25
  );
26
- void Effect.runPromise(Fiber.interrupt(fiber));
26
+ void Effect.runPromise(
27
+ Fiber.interrupt(fiber).pipe(
28
+ Effect.onInterrupt(() => Effect.logDebug('Fiber interrupted')),
29
+ ),
30
+ );
27
31
  };
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
33
  }, [effectRef, ...deps]);
29
34
  }
@@ -1,5 +1,5 @@
1
- import { Effect, Exit, Scope } from "effect";
2
- import { useEffect, useState } from "react";
1
+ import { Effect, Exit, Scope } from 'effect';
2
+ import { useEffect, useState } from 'react';
3
3
 
4
4
  export function useComponentScope(
5
5
  setup?: (scope: Scope.CloseableScope) => void,
@@ -1,4 +1,4 @@
1
- import { useRef } from "react";
1
+ import { useRef } from 'react';
2
2
 
3
3
  export function useLiveRef<T>(value: T): { current: T } {
4
4
  const ref = useRef(value);
@@ -1,6 +1,6 @@
1
- import { Effect, FiberHandle, Scope } from "effect";
2
- import { useComponentScope } from "./use-component-scope.js";
3
- import { useState } from "react";
1
+ import { Effect, FiberHandle, Scope } from 'effect';
2
+ import { useState } from 'react';
3
+ import { useComponentScope } from './use-component-scope.js';
4
4
 
5
5
  export function useRunEffectLatest<Args extends any[], A, E>(
6
6
  fn: (...args: Args) => Effect.Effect<A, E, never>,
@@ -18,7 +18,7 @@ export function useRunEffectLatest<Args extends any[], A, E>(
18
18
  return (...args: Args) => {
19
19
  if (!fiberHandle) {
20
20
  throw new Error(
21
- "useRunEffectLatest: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.",
21
+ 'useRunEffectLatest: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.',
22
22
  );
23
23
  }
24
24
 
@@ -1,6 +1,6 @@
1
- import { Effect, Fiber, FiberHandle, Scope } from "effect";
2
- import { useComponentScope } from "./use-component-scope.js";
3
- import { useEffect, useRef } from "react";
1
+ import { Effect, Fiber, FiberHandle, Scope } from 'effect';
2
+ import { useEffect, useRef } from 'react';
3
+ import { useComponentScope } from './use-component-scope.js';
4
4
 
5
5
  export function useRunEffectQueue<Args extends any[], A, E>(
6
6
  fn: (...args: Args) => Effect.Effect<A, E, never>,
@@ -31,6 +31,7 @@ export function useRunEffectQueue<Args extends any[], A, E>(
31
31
  });
32
32
  };
33
33
 
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
35
  useEffect(runFromQueue, [scope]);
35
36
 
36
37
  return (...args: Args) => {
@@ -1,6 +1,6 @@
1
- import { Effect, FiberSet, Scope } from "effect";
2
- import { useComponentScope } from "./use-component-scope.js";
3
- import { useState } from "react";
1
+ import { Effect, FiberSet, Scope } from 'effect';
2
+ import { useState } from 'react';
3
+ import { useComponentScope } from './use-component-scope.js';
4
4
 
5
5
  export function useRunEffect<Args extends any[], A, E>(
6
6
  fn: (...args: Args) => Effect.Effect<A, E, never>,
@@ -13,8 +13,11 @@ export function useRunEffect<Args extends any[], A, E>(
13
13
 
14
14
  return (...args: Args) => {
15
15
  if (!fiberSet) {
16
+ console.error(
17
+ 'useRunEffect: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.',
18
+ );
16
19
  throw new Error(
17
- "useRunEffect: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.",
20
+ 'useRunEffect: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.',
18
21
  );
19
22
  }
20
23