module
source
Tabular data from a src: where it comes from, how to ask for it, and how to read what comes back, from a CSV file to a statistics agency's API.
Everything here is plain code over crate::Request and crate::Response, so the browser, a prerender and a test all run the same path. Only send depends on where it's running.
Modules
- csv
CSV and TSV, as files are actually written: quoted fields with commas and newlines, doubled quotes, a BOM, CRLF, and comma, tab or semicolon.
- extract
Finding the rows in a JSON response.
- live
Data that keeps changing: timers, connections and what their messages do to a table. The browser supplies the actual timers and sockets through
set_host, so all of this runs the same under test. - load
A
srcand its options, the request they make, and reading the answer. - table
A table of typed columns: what every
srcturns into. - time
Time periods as statistics publish them:
2021,2023-Q1,2023-M03,2023-03,2023-03-15,Mar-2023and financial years (2022-23), read as decimal years so an axis spaces them truly.
Structs
- Column
A column of a table: its key and label, what it holds and is for, and how its values are ordered.
- Meta
What the source says about the data as a whole.
- Spec
What a component's
srcand related props ask for. - Table
Data read from a source: its columns and rows (records), with what the source says about it.
Enums
Functions
next_page
pub fn next_page(spec: &Spec, current: &Request, res: &Response) -> Option<Request>The next page of a response, if it has one and there are rows on this one.
next_page_is_none
pub fn next_page_is_none(current: &Request, res: &Response) -> boolWhether a response is complete, rather than one page of several.
note_browser_load
pub fn note_browser_load()Note that a source on the page being rendered loads (or refreshes, or listens) in the browser, so the page needs the runtime there.
parse
pub fn parse(spec: &Spec, res: &Response) -> Result<Table, Error>Read a response into a table and apply the spec's shaping.
parse_raw
pub fn parse_raw(spec: &Spec, res: &Response) -> Result<Table, Error>Read a response into a table, before any shaping.
record_baked
pub fn record_baked(key: &str, res: &Response)Keep a build-time response so the page can carry it to the browser.
send
pub fn send(req: Request, done: Done)Send a request. done may run before this returns, or later.
set_baked
pub fn set_baked(entries: BTreeMap<String, Response>)What the page carries, in the browser.
set_baked_json
pub fn set_baked_json(j: &Value)Read what the page carries (the JSON of BAKED_ID's element).
set_fetch_remote
pub fn set_fetch_remote(on: bool)Whether the build fetches other sites' data (with the blocking feature). Prerendering turns it on; elsewhere native code never touches the network.
set_loader
pub fn set_loader(f: impl Fn(Request, Done) + 'static)Set how requests are sent (the browser does this when the app starts; tests install a fake).
set_public_dir
pub fn set_public_dir(dir: Option<PathBuf>)Where the site's own files are read from during the build: public/ unless set (a workspace building several apps sets each one's).
take_baked
pub fn take_baked() -> BTreeMap<String, Response>Everything recorded since the last call (one page's worth).
take_browser_loads
pub fn take_browser_loads() -> boolWhether a source noted note_browser_load since the last call (one page's worth).
Constants
BAKED_ID
pub const BAKED_ID: &str = "weft-sources";The id of the script element carrying the build's responses.
STATUS
pub const STATUS: &str = "_status";Field on a row holding why its cells have no value: {key: marker}.
Type aliases
Shape
pub type Shape = Vec<Vec<Vec<(f64, f64)>>>;A map region's shape: polygons, each an outer ring and any holes, in longitude and latitude.