@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
45 lines (44 loc) • 943 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createDataReference = createDataReference;
function createDataReference() {
const snapshotRef = {
current: undefined
};
const eventsRef = {
current: []
};
const refresh = ({
deferred = false
} = {}) => {
const update = () => eventsRef.current.forEach(fn => fn());
if (deferred && typeof window !== 'undefined') {
requestAnimationFrame(update);
} else {
update();
}
};
const update = data => {
snapshotRef.current = data;
};
const cleanup = (fn = null) => {
if (fn) {
const index = eventsRef.current.indexOf(fn);
if (index !== -1) {
eventsRef.current.splice(index, 1);
}
} else {
eventsRef.current = [];
}
};
return {
refresh,
update,
cleanup,
snapshotRef,
eventsRef
};
}
//# sourceMappingURL=IsolationDataReference.js.map