1.0.0-beta.72 Big bada boom in data loading API
Updated data and metadata loading logic
The data loading logic in Discovery.js has been modified to consistently expect raw data and separate meta info, if provided. Previously, the Discovery.js app was designed to work exclusively with data generated by @discoveryjs/cli (either via a server or builder), which wrapped the data in an object { name, createdAt, elapsed, data: /* actual data */ } (combining actual data with meta information). As Discovery.js evolved, it gained the ability to load data from various data sources like url, file, stream, raw data, etc., which do not use the same wrapper. The differences in data structure made it challenging to create versatile apps that could load data from diverse sources in various ways. This issue became particularly significant with the addition of the embed API.
Starting with the latest release of @discoveryjs/cli, data is no longer wrapped, and meta info is provided differently. As a result, the Discovery.js app now handles data loading uniformly, regardless of the data source type.
To ensure compatibility with data using the old @discoveryjs/cli wrapper, code has been added to detect and unwrap the data during the transition period, allowing for a seamless experience.
Uniform load data methods
This release uniforms API shape responsible for data loading. This related to loadDataFrom* functions as well as App#loadDataFrom* methods. With the release now functions and methods have similar semantics, with a single exception for loadDataFromPush() which has no subject to load from:
loadDataFromUrl(url, options)loadDataFromEvent(event, options)loadDataFromFile(file, options)loadDataFromStream(stream, options)loadDataFromPush(options)
The options optional parameter an object which structure depends on a method. However, there are one common option resource, which specify metadata related to a loading dataset.
Changes
- Made internal navigation using anchors (
<a>tags) work without router extension enabled. Useignore-hrefclass on an anchor to prevent navigation byhrefattribute if needed - Added
permalinkaction to generate current state of an app (absolute page URL by default), it can be overridden by embedding host - Changed
Widget#setPageHash()to make leading#optional, i.e.Widget#setPageHash('#report')andWidget#setPageHash('report')give the same result now - Embed API:
- Reworked internals for more efficient data transfer, e.g. transfer a data stream intead of tranfering data with chunks
- Replaced
App#loadDatawithApp#uploadData(source, extractResourceMetadata)method, which takes source instead of a function returning a source - Added
setRouterPreventLocationUpdate()method for preloader and app to prevent location updates (and browser's history as well) on internal navigation - Added
setPageHash()method for preloader embed API
- Reworked loading data API and internals:
- Added support for loading binary encoded data (jsonxl snapshot 9)
- Added
Widget#datasetsand#.datasetsto store loaded datasets (data itself and its meta data as an object). Current APIs assume to work with a single dataset (data), so this list contains zero or one element for now. However, future version will allow to load and work with multiple datasets (still need to think about the details) - Added
datasetoption inWidget#setData()method options to provide dataset's attributes, which is optional and a dataset object will hasdatafield only if the option is not provided - Added
start(resource)method toloadFromPush()API - Changed loading data logic to always expect raw data and meta info specified aside (via
options) if provided (see release notes for details) - Changed preloader to pass
loadDataOptionsinto all the loading methods asoptions - Changed
Widget#setDataProgress(data, context, progressbar)signature intosetDataProgress(data, context, options), whereoptionsis an object{ dataset?, progressbar? } - Removed
#.nameand#.createdAt, use#.datasets[].resource | { name, createdAt }instead - Removed
datafromWindget#context, however,datais still available in a render context asdataof default dataset, i.e.#.datawhich the same as#.datasets[].data - Removed
Widget#dataLoadedand#.dataLoadedflags, useWidget#hasDatasets()method or#.datasetsin jora queries - Changes in
loadDataFromUrl()method:- Changed
getContentSizeoption to not takeurlparameter anymore - Changed the default
getContentSizehandler to preferX-File-Sizeheader overContent-Lengthheader - Added
getContentCreatedAtoption to specify a function to retrievecreatedAtfrom a fetch's response (by default, retrieve a value from theX-File-Created-Atheader if present, orLast-Modifiedheader otherwise) - Added
getContentEncodedSizeoption - Fixed a potential crash on JSON parse for a bad response with
application/jsoncontent type - Removed
dataFieldoption - Removed support for loading raw data using this function
- Changed
- Removed
Widget#lib