Any way to batch updates/subscribe to two atoms in Nanostores?

71 Views Asked by At

I'm exploring Nanostores as an alternative to Solid JS and I'm just wondering whether there is something equivalent to Solid's batch function, i.e.:

const x = atom(0);
const y = atom(0);

function handleMouseDown(event: MouseEvent) {
  // Some way to batch updates here?
  x.set(event.offsetX);
  y.set(event.offsetY);
}

document.body.addEventListener("mousedown", handleMouseDown);

// Such that there's only one update when *both* x and y change?
const xy = atom([0, 0]);
x.subscribe((v) => xy.set([v, xy.get()[1]]));
y.subscribe((v) => xy.set([xy.get()[0], v]));

xy.subscribe(console.log);
0

There are 0 best solutions below