humanmade / humanmade/repress

Add ability to short-circuit archive requests

Open
#34 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
82
Forks
8
PR merge metrics
No merged PRs in 30d

Description

In some cases, you may be able to short-circuit archive requests locally if you know how to match items on the client side.

For example, say you have a handler for posts, and you have dynamic archives using the slug:
```
props => {
const query = {
slug: props.slug,
};
posts.registerArchive( `slug/${ props.slug }`, query );
return `slug/${ props.slug }`;
}
```

As a developer, you know that WordPress de-duplicates slugs, so you can generate an authoritative search and skip the backend request if you happen to already have the post loaded in (from another archive/single request, e.g.).

It'd be good to have the ability to write a local matcher, which would still fall back to the backend. This local matcher would be treated as authoritative by Repress, so it should only be used when you know for certain that you're going to match.

Something like this:
```
posts.registerArchive( `slug/${ props.slug }`, query, {
localMatcher: posts => posts.filter( post => post.slug === props.slug,
} );
```

(Naming tbd)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.