Comparing version 0.4.5 to 0.4.6
@@ -62,9 +62,13 @@ "use strict"; | ||
function on(target, listener) { | ||
let free; | ||
if (!target) | ||
return; | ||
else if (target[0]) | ||
else if (target[0]) { | ||
target = target[0]; // box or selector or custom reactive | ||
} | ||
else { | ||
[target, free] = reactive_box_1.sel(target); | ||
} | ||
let value; | ||
const [get, free] = reactive_box_1.sel(target); | ||
const [run, stop] = reactive_box_1.expr(get, () => { | ||
const [run, stop] = reactive_box_1.expr(target, () => { | ||
const prev = value; | ||
@@ -74,3 +78,7 @@ listener((value = run()), prev); | ||
value = run(); | ||
const unsub = () => (free(), stop()); | ||
const unsub = () => { | ||
if (free) | ||
free(); | ||
stop(); | ||
}; | ||
if (context_unsubs) | ||
@@ -77,0 +85,0 @@ context_unsubs.push(unsub); |
{ | ||
"name": "realar", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "React state manager", | ||
@@ -91,3 +91,3 @@ "repository": { | ||
}, | ||
"gitHead": "fc67b18ffca5bb8ac391606b216ca4d8465aca2c" | ||
"gitHead": "60c507b53010e2af3fa1e7ba307d7e8f608d3e2d" | ||
} |
@@ -31,3 +31,5 @@ import { useRef, useReducer, useEffect, useMemo, FC } from 'react'; | ||
function action<T = void>(init?: T): { | ||
function action<T = void>( | ||
init?: T | ||
): { | ||
(data?: T): void; | ||
@@ -93,8 +95,14 @@ (): void; | ||
) { | ||
let free: (() => void) | undefined; | ||
if (!target) return; | ||
else if ((target as any)[0]) target = (target as any)[0]; // box or selector or custom reactive | ||
else if ((target as any)[0]) { | ||
target = (target as any)[0]; // box or selector or custom reactive | ||
} else { | ||
[target, free] = sel(target as any); | ||
} | ||
let value: T; | ||
const [get, free] = sel(target as any); | ||
const [run, stop] = expr(get, () => { | ||
const [run, stop] = expr(target as any, () => { | ||
const prev = value; | ||
@@ -104,3 +112,6 @@ listener((value = run() as any), prev); | ||
value = run() as any; | ||
const unsub = () => (free(), stop()); | ||
const unsub = () => { | ||
if (free) free(); | ||
stop(); | ||
}; | ||
if (context_unsubs) context_unsubs.push(unsub); | ||
@@ -107,0 +118,0 @@ return unsub; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25966
441