AIDA
AIDA

Reputation: 529

Does Falcor Router implement route ranking?

While looking into Faclor router I quite liked the feature of KeySets which allow a route to match on a set of entity keys in any combination, but it made me wonder about route ranking.

If I have a route: "titlesById[{integers:titleIds}]['name','year']"

and another route: "titlesById[{integers:titleIds}]['name']"

When I request only the name key, how does Falcor router determine which route to use. My concern is you may have a more efficient data access strategy for when multiple keys are accessed versus a single key.

Upvotes: 1

Views: 193

Answers (1)

ThePrimeagen
ThePrimeagen

Reputation: 4582

Yes and No.

It implements route precedence, meaning the following:

specific keys: 4 integers / ranges: 2 keys: 1

So ['name', 'year'] and ['name'] are equivalent in precedence.

But there is a problem with you specification. The Router does not allow the same precedence routes matching the same paths. So the following paths are equivalent in precedence and thus will throw an error upon Router construction.

{ route: 'titlesById[{integers:titleId}].name', get: ... },
{ route: 'titlesById[{ranges:titleId}].name', get: ... }, 
...

This will throw an error since both ranges and integers match the same set of incoming datas (numbers) and they both match the same route (titlesById, numbers, name). This extends to your example, you have two routes in which match the same path, this cannot happen (unless of course one route matches with a get handler and the other a set handler).

Upvotes: 2

Related Questions