@adyen/adyen-platform-experience-web
Version:

66 lines (65 loc) • 1.54 kB
JavaScript
import { assertReflexAction as c, unwrap as i } from "./helpers.js";
import { $globalReflexRegister as x } from "./register.js";
import { REF as _ } from "./constants.js";
import { struct as d } from "../../../utils/struct/main.js";
import { isNullish as b } from "../../../utils/value/is.js";
import { sameValue as p } from "../../../utils/value/compare.js";
const R = (n) => {
c(n);
const r = new WeakMap([[n, 1]]), e = (u) => {
if (p(t, u)) return;
const o = t;
n(t = u, o);
};
let t = null;
return Object.defineProperties(e, {
[_]: { value: e },
actions: {
value: d({
get: { value: r.get.bind(r) },
size: { value: 1 }
})
},
current: {
get: () => t,
set: e
}
});
}, $ = (n = x) => {
let r, e = null, t, u = !1;
const o = (l) => {
r = void 0, e = null, t = l, u = !1;
}, m = () => {
u || (f(), u = !0);
}, f = () => {
try {
if (!e) return;
n.unbind(e, t);
} catch {
}
};
return d({
action: { get: () => t },
reflex: { get: () => r },
release: { value: m },
update: { value: (l, s) => {
c(l), u && o(l);
const a = b(s) ? null : s;
if (t === l && e === a) {
if (r) return;
} else if (e) {
if (p(i(e), i(a))) {
r = n.bind(e, l), f(), t = l;
return;
}
f();
}
t = l, r = (e = a) ? n.bind(e, t) : R(t);
} }
});
};
export {
R as createIsolatedFauxReflex,
$ as createReflexContainer,
$ as default
};