cellplatform / platform-0.2.0

/sys (shared system modules)
Other
4 stars 2 forks source link

cmd: ("command") #195

Closed philcockfield closed 1 month ago

philcockfield commented 1 month ago

module: sys.ext.automerge

const cmd = Cmd.create<C>(doc);
const events = cmd.events(dispose$);

A distributed function ("command") invokation strategy using CRDT's as the underlying coordination transport to deliver the invoke (⚡️) event along with event payloads.

Then a strongly typed, elegant programming API that wraps the basic mechanic to make usage of the mechanism easy, simple, and consistent for common usecases.


"subroutine invocation with indirection"

"He listened to what Alan was saying and said, 'well you're not really sending messages' you're doing 'subroutine invocation with indirection' which was brilliant, that's a really brilliant idea. But what if you actually were sending messages?"

↑ Crockford on Carl Hewitt, reacting to Alan Kay and looking at SmallTalk in early 1970's at MIT — video timestamp


// Sample command type definitions:

type P = { a: number; b: number };
type R = { sum: number };
type E = t.CmdError & { code: number; type: 'bounds' };

type C = C1 | C2 | C3;
type C1 = t.CmdType<'add', P, C2, E>;
type C2 = t.CmdType<'add:res', R>;
type C3 = t.CmdType<'foo', { msg?: string }>;

const sum = ({ a, b }: P): R => ({ sum: a + b });

sample chained invocation call:

await cmd
  .invoke('add', 'add:res', { a: 1, b: 2 })
  .listen()
  .onError((e) => /* log error */)
  .onComplete((e) => /* success */)
  .promise();

TODO: collapse this further into strongly typed DX, for both client invokation calls, and server/handler setup.


smor-sys crdt-cell

Cmd is an implementation of this part of the abstract system diagram

image

philcockfield commented 1 month ago

timestamp

image
philcockfield commented 1 month ago

timestamp

image

"...he was born on the other side of a paradigm shift, so when he talks, nobody understands what he means because he's seeing things from a completely different perspective" - Douglas Crockford

ref

philcockfield commented 1 month ago

"subroutine invocation with indirection"

"He listened to what Alan was saying and said, 'well you're not really sending messages' you're doing 'subroutine invocation with indirection' which was brilliant, that's a really brilliant idea. But what if you actually were sending messages?"

↑ Crockford on Carl Hewitt, reacting to Alan Kay and looking at SmallTalk in early 1970's at MIT — video timestamp