@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 p } from "../../../utils/struct/main.js";
import { isNullish as b } from "../../../utils/value/is.js";
import { sameValue as d } from "../../../utils/value/compare.js";
const v = (n) => {
c(n);
const r = new WeakMap([[n, 1]]), e = (o) => {
if (d(t, o)) return;
const u = t;
n(t = o, u);
};
let t = null;
return Object.defineProperties(e, {
[_]: { value: e },
actions: {
value: p({
get: { value: r.get.bind(r) },
size: { value: 1 }
})
},
current: {
get: () => t,
set: e
}
});
}, $ = (n = x) => {
let r, e = null, t, o = !1;
const u = (l) => {
r = void 0, e = null, t = l, o = !1;
}, m = () => {
o || (a(), o = !0);
}, a = () => {
try {
if (!e) return;
n.unbind(e, t);
} catch {
}
};
return p({
action: { get: () => t },
reflex: { get: () => r },
release: { value: m },
update: { value: (l, s) => {
c(l), o && u(l);
const f = b(s) ? null : s;
if (t === l && e === f) {
if (r) return;
} else if (e) {
if (d(i(e), i(f))) {
r = n.bind(e, l), a(), t = l;
return;
}
a();
}
t = l, r = (e = f) ? n.bind(e, t) : v(t);
} }
});
};
export {
v as createIsolatedFauxReflex,
$ as createReflexContainer,
$ as default
};