question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make `Fig.Generator["trigger"]` more declarative

See original GitHub issue

Sanity checks

Feature Details

There are some things that currently happen imperatively that could happen declaratively.

  • Token length changes
  • Token length changes around a number, eg for 5: from 4>5, 4>6, 6>5, 6>4, etc.
  • Final index of one of N strings is changed, instead of just one
type Trigger =
  | string
  | ((newToken: string, oldToken: string) => boolean)
  | { on: "change" }
  | { on: "threshold"; length: number }
  | { on: "string"; string: string | string[] };

interface Generator {
  trigger: Trigger;
}

const _0: Generator = {
  // Trigger on every keystroke
  trigger: { on: "change" },
}

const _1: Generator = {
  // Trigger when length passes 5
  trigger: { on: "threshold", length: 5 },
}

const _2: Generator = {
  // Trigger when length changes to or from 0
  trigger: { on: "threshold", length: 0 },
}

const _3: Generator = {
  // Trigger when any of the last index of any of the strings are changed
  trigger: { on: "string", string: [":", ","] },
}

// Implementation / equivalent `trigger` functions

// change:
// () => true

// threshold:
// (curr, prev) => (curr.length <= length && prev.length >= length) || (curr.length >= length && prev.length <= length)

// string:
// (curr, prev) => Math.max(...makeArray(strings).map((string) => curr.lastIndexOf(string))) !== Math.max(...makeArray(strings).map((string) => prev.lastIndexOf(string)))

cc @fedeci - are there any extras you can think of? Better names? I think this covers the main use-cases.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
fedecicommented, Aug 23, 2022
type Trigger =
  | string
  | ((newToken: string, oldToken: string) => boolean)
  | { on: "change" }
  | { on: "threshold"; length: number }
  | { on: "match"; string: string | string[] };

I think this is a better naming, and I like the idea of having a sugar on top of trigger.

1reaction
SeparateRecordscommented, Aug 23, 2022

Definitely wouldn’t remove the ability to use a function, but making it simpler to do the most common things is good

Just checked in withfig/autocomplete and this covers almost every case where there’s currently a function for trigger

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · withfig/autocomplete - GitHub
Make Fig.Generator["trigger "] more declarative codebase:autocomplete-app schema Anything related to the spec API type:feature-request.
Read more >
Contents - computer science at N.C. State
Also, formal methods are the most effective when included in tools and used ... An important practical consideration is to make the semantics...
Read more >
AP5 Reference Manual
First, it allows you to choose a representation of data that you think will make your program more efficient. You can even create...
Read more >
Multiagent Systems : A Modern Approach to Distributed ...
To make the above considerations more concrete, a closer look has to be taken on multiagent systems and thus on.
Read more >
Grounded discourse representation theory - Academia.edu
This in fact is the intuitively more fundamental type of reference: in order to make referential use of natural language, there must first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found