use-effect-ts 0.0.7 → 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 +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/use-component-lifecycle.d.ts +2 -2
- package/dist/use-component-lifecycle.d.ts.map +1 -1
- package/dist/use-component-lifecycle.js +5 -4
- package/dist/use-component-scope.d.ts +1 -1
- package/dist/use-component-scope.js +2 -2
- package/dist/use-live-ref.js +1 -1
- package/dist/use-run-effect-latest.d.ts +1 -1
- package/dist/use-run-effect-latest.js +4 -4
- package/dist/use-run-effect-queue.d.ts +1 -1
- package/dist/use-run-effect-queue.d.ts.map +1 -1
- package/dist/use-run-effect-queue.js +4 -3
- package/dist/use-run-effect.d.ts +1 -1
- package/dist/use-run-effect.d.ts.map +1 -1
- package/dist/use-run-effect.js +5 -4
- package/package.json +26 -24
- package/src/index.ts +6 -6
- package/src/use-component-lifecycle.ts +9 -4
- package/src/use-component-scope.ts +2 -2
- package/src/use-live-ref.ts +1 -1
- package/src/use-run-effect-latest.ts +4 -4
- package/src/use-run-effect-queue.ts +4 -3
- package/src/use-run-effect.ts +7 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { useComponentLifecycle } from
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
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
|
|
2
|
-
export declare function useComponentLifecycle(effect: Effect.Effect<
|
|
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,
|
|
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
|
|
2
|
-
import { useEffect } from
|
|
3
|
-
import { useLiveRef } from
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { Effect, Exit, Scope } from
|
|
2
|
-
import { useEffect, useState } from
|
|
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(() => {
|
package/dist/use-live-ref.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Effect } from
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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(
|
|
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 +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,
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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);
|
package/dist/use-run-effect.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Effect } from
|
|
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,
|
|
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"}
|
package/dist/use-run-effect.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Effect, FiberSet, Scope } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
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
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
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
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
"
|
|
17
|
-
"src/",
|
|
20
|
+
"LICENCE",
|
|
18
21
|
"README.md",
|
|
19
|
-
"
|
|
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.
|
|
30
|
-
"react": ">=
|
|
26
|
+
"effect": ">=3.19.14",
|
|
27
|
+
"react": ">=19.2.3"
|
|
31
28
|
},
|
|
32
|
-
"
|
|
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
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
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,6 +1,6 @@
|
|
|
1
|
-
import { Effect, Fiber, Scope } from
|
|
2
|
-
import { useEffect } from
|
|
3
|
-
import { useLiveRef } from
|
|
1
|
+
import { Effect, Fiber, Scope } from 'effect';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useLiveRef } from './use-live-ref.js';
|
|
4
4
|
|
|
5
5
|
export function useComponentLifecycle<A, E>(
|
|
6
6
|
effect: Effect.Effect<A, E, Scope.Scope>,
|
|
@@ -23,7 +23,12 @@ export function useComponentLifecycle<A, E>(
|
|
|
23
23
|
yield* Scope.close(scope, exit);
|
|
24
24
|
}),
|
|
25
25
|
);
|
|
26
|
-
void Effect.runPromise(
|
|
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
|
|
2
|
-
import { useEffect, useState } from
|
|
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,
|
package/src/use-live-ref.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Effect, FiberHandle, Scope } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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) => {
|
package/src/use-run-effect.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Effect, FiberSet, Scope } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
20
|
+
'useRunEffect: No scope available, effect will not run. Consider using useComponentLifecycle to call initial run.',
|
|
18
21
|
);
|
|
19
22
|
}
|
|
20
23
|
|