collectype / factory/objects/objectPrototypeRelation / objectPrototypeRelationFactory
objectPrototypeRelationFactory<
T,C>(ctx,oper): <K>(field,proto) =>C
Defined in: factory/objects/objectPrototypeRelation.ts:40
Creates a predicate filter for object prototype relations using PredicType.object.prototypeRelation.
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.
ObjectPrototypeRelationOper
The prototype relation operation to perform (see PredicType.object.prototypeRelation).
Returns a function that takes a field (of type object on T) and a prototype, and applies the object prototype relation predicate to filter the context.
<
K>(field,proto):C
K extends string | number | symbol
K
any
C
// Example: Composing an object prototype relation filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { objectPrototypeRelationFactory } from 'collectype';
type Person = { name: string; meta: object };
class PersonFunctions extends BaseFunctions<Person> {
objectHasPrototype = objectPrototypeRelationFactory<Person, this>(this, 'isPrototypeOf');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', meta: Object.create(Array.prototype) },
{ name: 'Bob', meta: {} },
{ name: 'Eve', meta: [] }
];
const fn = new PersonFunctions(people);
const filtered = fn.objectHasPrototype('meta', Array.prototype);
// filtered contains the items where 'meta' has Array.prototype as its prototype
PredicType.object.prototypeRelation for prototype checks on object fields.