@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
37 lines (36 loc) • 776 B
JavaScript
//#region src/lib/core/current-value.ts
/**
* Creates a writable value with immediate subscription semantics.
*/
function createCurrentWritable(initialValue, onChange) {
let current = initialValue;
const subscribers = /* @__PURE__ */ new Set();
const notify = (value) => {
for (const run of subscribers) run(value);
};
const set = (value) => {
if (Object.is(current, value)) return;
current = value;
notify(value);
onChange?.(value);
};
return {
get current() {
return current;
},
subscribe(run) {
subscribers.add(run);
run(current);
return () => {
subscribers.delete(run);
};
},
set,
update(updater) {
set(updater(current));
}
};
}
//#endregion
export { createCurrentWritable };
//# sourceMappingURL=current-value.js.map