vincjo / datatables

A toolkit for creating datatable components with Svelte
https://vincjo.fr/datatables
MIT License
363 stars 15 forks source link

$$Generic does not exist #45

Closed SrZorro closed 11 months ago

SrZorro commented 11 months ago
There are 15 files that have the following code: 15 results - 15 files src/lib/local/Datatable.svelte: 3 4: type T = $$Generic 5 src/lib/local/Pagination.svelte: 3 4: type T = $$Generic 5 src/lib/local/RowCount.svelte: 3 4: type T = $$Generic 5 src/lib/local/RowsPerPage.svelte: 3 4: type T = $$Generic 5 src/lib/local/Search.svelte: 3 4: type T = $$Generic 5 src/lib/local/Th.svelte: 3 4: type T = $$Generic 5 src/lib/local/ThFilter.svelte: 3 4: type T = $$Generic 5 src/lib/remote/Datatable.svelte: 3 4: type T = $$Generic 5 src/lib/remote/Pagination.svelte: 3 4: type T = $$Generic 5 src/lib/remote/RowCount.svelte: 3 4: type T = $$Generic 5 src/lib/remote/RowsPerPage.svelte: 3 4: type T = $$Generic 5 src/lib/remote/Search.svelte: 3 4: type T = $$Generic 5 src/lib/remote/Th.svelte: 3 4: type T = $$Generic 5 src/lib/remote/ThFilter.svelte: 3 4: type T = $$Generic 5 src/routes/(local)/test/search-scope/Search.svelte: 3 4: type T = $$Generic 5
    type T = $$Generic<Row>
    export let handler: DataHandler<T>

What is $$Generic for?

Why its not:

export let handler: DataHandler<Row>

Directly without the T?

vincjo commented 11 months ago

Did you get an error or something?

Here are the explanations:

31

Generic extends type Row relying on your data input. It gives autocompletion and error alerts.

SrZorro commented 11 months ago

Did you get an error or something?

Nop, I was just wondering from where that $$Generic type was comming from while reading the code. Im trying to make your library scroll to load more content instead of pagination and while reading the source code I saw that type but didn't know what it does

Now that I think it this issue should had been a discussion Q&A instead of an issue

Generic extends type Row relying on your data input. It gives autocompletion and error alerts.

Oh I see, $$Generic its a magic type from Svelte, I searched the svelte docs but there is no reference to that type, but checking the language-tools from Svelte there is the code that handles the $$Generic type

Thanks for the aclaration 👍

I was going to make the suggestion to change the handler from props to context so its not needed to pass {handler} everywhere, but I guess its needed like that to make the generic work in cases like Th and ThFilter

vincjo commented 11 months ago

Prop drilling seems acceptable to me at the moment. I don't know of an easier way, but very open to suggestions that improve the design. thank you for your feedback