Skip to content
On this page

Farfetched and Atomic Router

Integration is distributed as a separate package, you have to install it and its peer dependencies before usage:

sh
pnpm install atomic-router @farfetched/atomic-router
sh
yarn add atomic-router @farfetched/atomic-router
sh
npm install atomic-router @farfetched/atomic-router

API

WARNING

Atomic Router is still in development, so the API is not stable yet. This integration is tested with atomic-router@0.6.3, but it should work with any version of atomic-router.

Integration provides the way to use any Query in chainRoute operator. It has two options to transform Query to the shape that chainRoute expects:

freshChain

After opening a route with freshChain, .refresh Event would be executed. So, Query will be executed only if it is already .$stale.

ts
import { createJsonQuery } from '@farfetched/core';
import { freshChain } from '@farfetched/atomic-router';
import { chainRoute, createRoute } from 'atmoic-router';

const postRoute = createRoute<{ postId: string }>();

const postQuery = createJsonQuery({
  /* ... */
});

const postLoadedRoute = chainRoute({
  route: postRoute,
  ...freshChain(postQuery),
});

startChain

After opening a route with startChain, .start Event would be executed. So, Query will be executed unconditionally.

ts
import { createJsonQuery } from '@farfetched/core';
import { startChain } from '@farfetched/atomic-router';
import { chainRoute, createRoute } from 'atmoic-router';

const postRoute = createRoute<{ postId: string }>();

const postQuery = createJsonQuery({
  /* ... */
});

const postLoadedRoute = chainRoute({
  route: postRoute,
  ...startChain(postQuery),
});

Released under the MIT License.