Skip to content

crelte / queries / varsIdsEqual

Function: varsIdsEqual()

ts
function varsIdsEqual(a, b): boolean;

Checks if two id arrays are equal

The first argument needs to come from a vars.ids() variable. The second argument should come from a query, where the output is trusted.

Example

js
export const variables = {
    categories: vars.ids()
};

export const caching: Caching<typeof variables> = (res, vars) => {
    // res is the graphql response
    return varsIdsEqual(vars.categories, res.categories);
};

Note

The following cases are considered equal:

js
varsIdsEqual(null, null);
varsIdsEqual([], null);
varsIdsEqual([1,2], ['2',1]);

These are not equal:

js
varsIdsEqual([1], null);
varsIdsEqual([2,1], [2,1]); // because the second arg gets ordered

Parameters

a

number[] | null | undefined

b

(string | number)[] | null | undefined

Returns

boolean