KeysAnd
Create a logical AND of keys and their values.
new QueryLogic.KeysAnd(values)
Creates a logical AND of the keys and values in values. The following
creates a representation of the set of objects whose first property is "Justin"
and age property is 35:
import {QueryLogic} from "can";
const isJustinAnd35 = new QueryLogic.KeysAnd({
first: "Justin",
age: 35
});
console.log( isJustinAnd35.values ); //-> {first: Justin, age: 35}
Parameters
- values
{Object}:An object of key-value pairs. The values of keys might be set representations like
GreaterThan.
Use
Instances of KeysAnd can be used to compare to other KeysAnd set.intersection, set.difference, and
set.union. For example:
import {QueryLogic} from "can";
const isJustinAnd35 = new QueryLogic.KeysAnd({
first: "Justin",
age: 35
});
const isChicago = new QueryLogic.KeysAnd({
location: "Chicago"
});
const intersect = QueryLogic.intersection( isJustinAnd35, isChicago )
console.log( intersect.values );//-> {first: "Justin", age: 35, location: "Chicago"}
KeysAnd can also be used to test if an object belongs to the set:
import {QueryLogic} from "can";
const isJustinAnd35 = new QueryLogic.KeysAnd({
first: "Justin",
age: 35
});
const matchesKeys = isJustinAnd35.isMember({
first: "Justin",
age: 35,
location: "Chicago"
});
console.log( matchesKeys ); //-> true
const matchesOneKey = isJustinAnd35.isMember({
first: "Payal",
age: 35,
location: "Chicago"
});
console.log( matchesOneKey ); //-> false
KeysAnd can be used recursively to test membership. For example:
import {QueryLogic} from "can";
const isJustinPostCollege = new QueryLogic.KeysAnd({
name: {first: "Justin"},
age: new QueryLogic.GreaterThan(22)
});
const olderThan = isJustinPostCollege.isMember({
name: {first: "Justin", last: "Meyer"},
age: 36
});
console.log( olderThan ); //-> true