jwillinghalpern / fm-gofer

An easy fetch-like promise library for FileMaker WebViewer apps and widgets.
ISC License
19 stars 2 forks source link

New function to just send data without waiting (and new syntax ideas) #41

Open jwillinghalpern opened 2 months ago

jwillinghalpern commented 2 months ago

The rationale for yeet is that I somewhat frequently see people wanting the behavior of OnFmReady without needing to await results from fm, that is, they just want FileMaker.PerformScript to work without worrying if it's loaded or not. One option is just to auto-implement OnFmReady when importing fmgofer, and having it automatically proxy FileMaker. Another option, is to just create a function like yeet, which is more explicit (the silly name makes that claim especially arguable, I know.)

The rationale for the new syntax ideas below is that I sometimes wish I'd chosen an options object as the second parameter from the very beginning, mimicking the fetch interface, but alas at the time I wanted the API to mirror FileMaker.PerformScript (and still think that was a pretty good idea).

// just call an fm script without waiting for response
// FMGofer.yeet('my script', {param: 'my param', scriptOption: 5});

function yeet(
  script: string, 
  options?: {
    param?: string,
    scriptOption?: number,
  }
) -> void;

// Sugar for FMGofer.PerformScriptWithOption
// const res = await FMGofer.gofer('my script', {param: 'hi', 'scriptOption: 5});

async function gofer(
  script: string,
  options: {
    param?: string,
    scriptOption?: number,
    timeout?: number,
    timeoutMessage?: string,
  }
) -> FMGPromise;