Connects to an endpoint to gather data.

Combines the possibility of loading data from a REST, GraphQL or simple text endpoint. The returned data can be a JSON object, HTMLElements or text depending of the used transfer type. It uses hylo-graphql when the connection type is set to "graph".

Properties

apiKey: string

An API key which will be added to the header of the request in the form of "Authorization": "Token apiKey"

This value is set globally. If it is set for one hylo-data-connector, it is set for all. If you change it for one, you change the value for all hylo-data-connector.

apiKeyLocal: string

An API key which will be added to the header of the request in the form of "Authorization": "Token apiKeyLocal"

This value is local and only applies to this component. It overwrites the global apiKey. To unset a global apiKey set this value to an empty string.

cache: boolean

Caches the requests and returns the results of previously made requests instead of making a new request if the "url", "apiKey", "query" and "parameters" are exact matches.

Only successful requests which return content are cached.

Only available for requests of type "graph".

errorLog: boolean

In case of an error in a GraphQL call, console.log extensive error log.

filter: HTMLHyloFilterManagerElement

Parameters added to the request. The parameters are retrieved from the hylo-filter-manager through the getFormValues() function.

items: string

A css query which marks elements in the loaded markup.

If set, the loaded data has to be html markup and the load promise resolves with a NodeListOf<HTMLElement> of the elements which fit the css query.

Keep in mind that the html markup is not processed, no Javascript run and no WebComponents are initialised yet. It is the raw html returned from the backend.

Works only with type "post" and "get".

noLoader: boolean

By default, the connector looks for a hylo-loader component on the page. If found, it uses it. With "noLoader" you can disable the use of the hylo-loader component.

parameters: {
    [key: string]: string | number | boolean | string[] | number[] | boolean[];
} = {}

Parameters added to the request in the form of a key/value object. "key"s will be overwritten by "filter" data when sending as "post" or "graph".

Type declaration

  • [key: string]: string | number | boolean | string[] | number[] | boolean[]
query: string

A GraphQL query as string (compatible with graphqlbuilder.stringRequest(...)). Only used and has to be set with type "graph".

The loaded data of a GraphQL call has to be JSON and the load promise resolves with this JSON object.

type: "get" | "post" | "graph" = 'get'

The type of the request.

"post" and "graph" are sending its data as JSON object.

url: string

The url of the request.

If none is set, the current url is used without search query string or hash tag.

Methods

  • Returns the unmodified result of the last successful call.

    Returns Promise<any>

  • Is the component ready to load data or is data being loaded right now.

    Returns Promise<boolean>

  • Loads data.

    The returned promise resolves with "null" if the component is not ready, busy because its loading data right now, or it got stopped. The returned promise resolves with "false" if an error occurs.

    "parameters" "key"s will overwrite any other data when sending as "post" or "graph".

    Parameters

    • parameters: {
          [key: string]: string | number | boolean | string[] | number[] | boolean[];
      } = {}

      additional parameters added to the request in the form of a key/value object

      • [key: string]: string | number | boolean | string[] | number[] | boolean[]

    Returns Promise<any>

  • Resolves when the component is ready to load new data.

    Returns Promise<null>

  • Stops the loading process. The load promise is still resolved but with a value of "null".

    If a loading process is in progress, the load promise resolves with "null".

    Should be called with "await" or further actions of this connector should be placed into ".then()".

    Returns Promise<void>

Events

hyloLoaded: EventEmitter<any>

Fires when a loading process finished. Emits the result.

hyloLoading: EventEmitter<any>

Fires when a loading process starts.

Generated using TypeDoc