Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more documentation about completion/link/filter to README #48

Open
rouilj opened this issue Jul 17, 2024 · 4 comments
Open

Add more documentation about completion/link/filter to README #48

rouilj opened this issue Jul 17, 2024 · 4 comments
Labels

Comments

@rouilj
Copy link

rouilj commented Jul 17, 2024

I want to use a tagging component for adding keywords to an item. There can be thousands of keywords,
so I want to have:

  • the user start typing a matching keyword
  • perform a query, using the currently typed match, to a web server after a short delay
  • get a json response with suitable matches
  • allow the user to choose a match

Thanks.

@jcubic
Copy link
Owner

jcubic commented Jul 17, 2024

Look at the signature of completion:

completion {list: string[] | function(): Promise(string[])|string[], delay: miliseconds, min_length: number}

This is pseudo TypeScript.

You can use:

var tags = tagger(input, {
    completion: {
        list(str) {
            return fetch(`/api/completion?text=${str}`).then(res => res.json());
        },
        delay: 500,
        min_length: 2
    }
});

There is only missing argument to the function in README.

@jcubic
Copy link
Owner

jcubic commented Jul 17, 2024

I've added some documentation to the demo. There is also a need to add some docs to README.

@jcubic jcubic added the good first issue Good for newcomers label Jul 17, 2024
@jcubic jcubic changed the title Is there an example of using completion() to query a remote json endpoint for matching values? Add more documentation about completion/link/filter to README Jul 17, 2024
@rouilj
Copy link
Author

rouilj commented Jul 17, 2024

Typescript signatures aren't my thing. I assume the signature should be interpreted as:
a function that takes (a currently undocumented) string argument and returns either a
Promise that resolves to a list/array of strings, or returns a list/array of strings directly.
Am I interpreting that correctly?

In my case I guess I would need to create a new Promise that wraps the fetch and changes
the shape of res.json to return a list of strings as the returned value from the search (for first) looks like:

{
    "data": {
        "collection": [
            {
                "id": "3",
                "link": "https://endpoint.example.com/ep/rest/data/keyword/3",
                "name": "First Time Failure"
            }
        ],
        "@total_size": 1
    }
}

@jcubic
Copy link
Owner

jcubic commented Jul 17, 2024

Yes, exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants