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

fix(vega-typings): narrow type signature for vega-loader.http #3312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hydrosquall
Copy link
Member

@hydrosquall hydrosquall commented Sep 29, 2021

Motivation

  • Providing a custom data fetcher, and noticed the response type could be narrowed.
  • Checked vega-loader, I think it's already behaving as if this type is a Response rather than a string. (You can't use fetch directly, you have to wrap it so that it returns a string. See comment below for a usage example. )

References

@hydrosquall hydrosquall self-assigned this Sep 29, 2021
@hydrosquall
Copy link
Member Author

hydrosquall commented Sep 29, 2021

I misspoke - it turns out you can't use fetch with loader.http directly, you have to wrap it in a function that returns a string. Something to this effect works as a default fetching function.

return fetch(url, options).then(response => {
            if (response.ok) {
                return response.text();
            }
            return response.text().then(text => {
                throw new Error(text);
            });
        });

@domoritz
Copy link
Member

domoritz commented Sep 29, 2021

In

type = options && options.response,
, we read response, which I don't see in RequestInit. Are you sure the type is right?

@hydrosquall
Copy link
Member Author

hydrosquall commented Sep 30, 2021

@domoritz, ah, good catch. I referring to this comment from the README.md, but you're right that RequestInit properties are not here.

From logging output at runtime,

Image 2021-09-30 at 2 24 50 PM

this is where the options object is populated.

https://github.com/vega/vega/blob/02d79dddb2850a24abfe6a4ebaf8823548709bb5/packages/vega-dataflow/src/dataflow/load.js#L42-L4

The response type would be one of these, or text.

dsv: dsv,
csv: delimitedFormat(','),
tsv: delimitedFormat('\t'),
json: json,
topojson: topojson

Do you think the fix here would be to update the README for vega-loader (text copied below), update the implementation, or both?

If provided, the options argument may include any valid fetch RequestInit properties. The provided options will be combined with any default options passed to the loader constructor under the http property.

@domoritz
Copy link
Member

For questions about the code and readme, @jheer knows best. The typings should follow the implementation.

@domoritz domoritz requested a review from jheer January 12, 2022 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants