Skip to content
On this page

connectQuery

Creates static connection between Queries. Every time when source Queries successfully done, target Query will start with a data from source as parameters.

Formulae

connectQuery({ source, target, filter? })

This form is used for target Query without parameters. It does not pass any data to target.

since v0.12 Optional filter function can be used to filter out unnecessary updates. It accepts an object with the shape from source, each field contains result and params of the corresponding Query and returns true if target Query should be started.
ts
const languagesQuery: Query<unknown, unknown, unknown>;
const blocksQuery: Query<unknown, unknown, unknown>;

const contentQuery: Query<void, unknown, unknown>;

connectQuery({
  source: { language: languagesQuery, blocks: blocksQuery },
  target: contentQuery,
});

connectQuery({ source, fn, target, filter? })

This form is used for target Query with parameters. It gets results and parameters of source, transforms it through fn and uses it for target Query.

fn accepts an object with the shape from source, each field contains result and params of the corresponding Query and returns an object with a single field params which is used to start target Query.

since v0.12 Optional filter function can be used to filter out unnecessary updates. It accepts an object with the shape from source, each field contains result and params of the corresponding Query and returns true if target Query should be started.
ts
const blocksQuery: Query<unknown, string, unknown>;
const blocksQuery: Query<unknown, string[], unknown>;

const contentQuery: Query<{ language: string; ids: string[] }, unknown, unknown>;

connectQuery({
  source: { language: languagesQuery, blocks: blocksQuery },
  fn({ language, blocks }) {
    // language.params contains parameters of the `languagesQuery`
    // language.result contains result of the `languagesQuery`

    // blocks.params contains parameters of the `blocksQuery`
    // blocks.result contains result of the `blocksQuery`

    return { params: { lang: language.result, ids: blocks.result } };
  },
  target: contentQuery,
});

Showcases

Released under the MIT License.