consolidate properties
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
31e0d74adc
commit
13775f897c
1 changed files with 5 additions and 7 deletions
|
@ -45,14 +45,10 @@ interface IOptions<T extends {}> {
|
||||||
*/
|
*/
|
||||||
export default class QueryMatcher<T extends Object> {
|
export default class QueryMatcher<T extends Object> {
|
||||||
private _options: IOptions<T>;
|
private _options: IOptions<T>;
|
||||||
private _keys: IOptions<T>["keys"];
|
|
||||||
private _funcs: Required<IOptions<T>["funcs"]>;
|
|
||||||
private _items: Map<string, {object: T, keyWeight: number}[]>;
|
private _items: Map<string, {object: T, keyWeight: number}[]>;
|
||||||
|
|
||||||
constructor(objects: T[], options: IOptions<T> = { keys: [] }) {
|
constructor(objects: T[], options: IOptions<T> = { keys: [] }) {
|
||||||
this._options = options;
|
this._options = options;
|
||||||
this._keys = options.keys;
|
|
||||||
this._funcs = options.funcs || [];
|
|
||||||
|
|
||||||
this.setObjects(objects);
|
this.setObjects(objects);
|
||||||
|
|
||||||
|
@ -77,11 +73,13 @@ export default class QueryMatcher<T extends Object> {
|
||||||
// type for their values. We assume that those values who's keys have
|
// type for their values. We assume that those values who's keys have
|
||||||
// been specified will be string. Also, we cannot infer all the
|
// been specified will be string. Also, we cannot infer all the
|
||||||
// types of the keys of the objects at compile.
|
// types of the keys of the objects at compile.
|
||||||
const keyValues = _at<string>(<any>object, this._keys);
|
const keyValues = _at<string>(<any>object, this._options.keys);
|
||||||
|
|
||||||
for (const f of this._funcs) {
|
if (this._options.funcs) {
|
||||||
|
for (const f of this._options.funcs) {
|
||||||
keyValues.push(f(object));
|
keyValues.push(f(object));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const [index, keyValue] of Object.entries(keyValues)) {
|
for (const [index, keyValue] of Object.entries(keyValues)) {
|
||||||
if (!keyValue) continue; // skip falsy keyValues
|
if (!keyValue) continue; // skip falsy keyValues
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue