collectype / factory/queries/queryState / queryStateFactory
queryStateFactory<
T,C>(ctx,oper): <K>(field) =>C
Defined in: factory/queries/queryState.ts:39
Creates a predicate filter for query state checks using PredicType.query.state.
T
The item type in the collection.
C extends Wherable<T, C>
The Wherable context type (must extend Wherable<T, C>).
C
The context (usually a collection) supporting the where method.
QueryStateOper
The query state operation to perform.
Returns a function that takes a query field on T, checks its state, and filters the context.
<K>(field) => C
// Example: query state filter with URL
import { BaseFunctions, queryStateFactory } from 'collectype';
type Post = { id: number; query: URL };
class PostFunctions extends BaseFunctions<Post> {
queryIsEmpty = queryStateFactory<Post, this>(this, 'is_empty');
}
const posts: Post[] = [
{ id: 1, query: new URL('https://example.com/?tag=ts') },
{ id: 2, query: new URL('https://example.com/') }
];
const fn = new PostFunctions(posts);
const filtered = fn.queryIsEmpty('query');
// filtered contains items whose query is empty
URL and URLSearchParams.PredicType.query.state.