jazz icon indicating copy to clipboard operation
jazz copied to clipboard

Feature request: chainable methods

Open frolic opened this issue 2 months ago • 2 comments

I'm curious what ya'll think of chainable methods for better ergonomics in common patterns.

Currently, if I want to make a write-only list, I'd do something like

export const FriendRequests = co.list(co.account());

const friendRequestsGroup = co.group().create();
friendRequestsGroup.addMember("everyone", "writeOnly");
const friendRequests = FriendRequests.create([], friendRequestsGroup);

But if methods like .addMember returned this group, I could additionally do

const friendRequests = FriendRequests.create([], co.group().create().addMember("everyone", "writeOnly"));

I'm happy to take a stab at a PR if ya'll are aligned with this direction.

frolic avatar Oct 14 '25 13:10 frolic

In the meantime, I am using this

export function createEveryoneGroup(role: "writer" | "reader" | "writeOnly") {
  const group = co.group().create();
  group.addMember("everyone", role);
  return group;
}

const friendRequests = FriendRequests.create([], createEveryoneGroup("writeOnly"));

frolic avatar Oct 14 '25 13:10 frolic

from guido:

Looks good to me.

Feel free to open a PR.

linear[bot] avatar Oct 16 '25 14:10 linear[bot]