BREAKING CHANGE(objectmap): switch to async behaviours
This commit is contained in:
parent
15b8fe406a
commit
f402e55ff3
@ -52,7 +52,7 @@ tap.test('Objectmap.forEach -> should correctly run a function forEach map objec
|
||||
tap.test('lik.Objectmap.find() -> should correctly find an object', async () => {
|
||||
let myObject = { propOne: 'helloThere', propTwo: 'helloAnyway' };
|
||||
testObjectmap.add(myObject);
|
||||
let referenceObject = testObjectmap.find((itemArg) => {
|
||||
let referenceObject = await testObjectmap.find(async (itemArg) => {
|
||||
return itemArg.propOne === 'helloThere';
|
||||
});
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
|
@ -76,7 +76,7 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
||||
* @param objectArg removes an interest from the InterestMap
|
||||
*/
|
||||
public removeInterest(interestArg: Interest<DTInterestId, DTInterestFullfillment>) {
|
||||
const interestToRemove = this.interestObjectMap.findOneAndRemove((interestArg2) => {
|
||||
const interestToRemove = this.interestObjectMap.findOneAndRemoveSync((interestArg2) => {
|
||||
return interestArg.comparisonString === interestArg2.comparisonString;
|
||||
});
|
||||
}
|
||||
@ -94,7 +94,7 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
||||
* @param comparisonStringArg
|
||||
*/
|
||||
public checkInterestByString(comparisonStringArg: string): boolean {
|
||||
const foundInterest = this.interestObjectMap.find((interest) => {
|
||||
const foundInterest = this.interestObjectMap.findSync((interest) => {
|
||||
return interest.comparisonString === comparisonStringArg;
|
||||
});
|
||||
if (foundInterest) {
|
||||
@ -121,7 +121,7 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
||||
*/
|
||||
public findInterest(objectArg: DTInterestId): Interest<DTInterestId, DTInterestFullfillment> {
|
||||
const comparableString = this.comparisonFunc(objectArg);
|
||||
const interest = this.interestObjectMap.find((interestArg) => {
|
||||
const interest = this.interestObjectMap.findSync((interestArg) => {
|
||||
return interestArg.comparisonString === comparableString;
|
||||
});
|
||||
return interest; // if an interest is found, the interest is returned, otherwise interest is null
|
||||
|
@ -13,10 +13,14 @@ export interface IObjectmapForEachFunction<T> {
|
||||
(itemArg: T): void;
|
||||
}
|
||||
|
||||
export interface IObjectmapFindFunction<T> {
|
||||
export interface IObjectmapFindFunctionSync<T> {
|
||||
(itemArg: T): boolean;
|
||||
}
|
||||
|
||||
export interface IObjectmapFindFunction<T> {
|
||||
(itemArg: T): Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface IObjectMapEventData<T> {
|
||||
operation: 'add' | 'remove';
|
||||
payload: T;
|
||||
@ -121,7 +125,11 @@ export class ObjectMap<T> {
|
||||
/**
|
||||
* find object
|
||||
*/
|
||||
public find(findFunction: IObjectmapFindFunction<T>): T {
|
||||
public async find(findFunction: IObjectmapFindFunction<T>): Promise<T> {
|
||||
return this.fastMap.find(findFunction);
|
||||
}
|
||||
|
||||
public findSync(findFunction: IObjectmapFindFunctionSync<T>): T {
|
||||
for (const keyArg of this.fastMap.getKeys()) {
|
||||
if (findFunction(this.fastMap.getByKey(keyArg))) {
|
||||
return this.getMappedUnique(keyArg);
|
||||
@ -132,8 +140,15 @@ export class ObjectMap<T> {
|
||||
/**
|
||||
* finds a specific element and then removes it
|
||||
*/
|
||||
public findOneAndRemove(findFunction: IObjectmapFindFunction<T>): T {
|
||||
const foundElement = this.find(findFunction);
|
||||
public async findOneAndRemove(findFunction: IObjectmapFindFunction<T>): Promise<T> {
|
||||
const foundElement = await this.find(findFunction);
|
||||
if (foundElement) {
|
||||
this.remove(foundElement);
|
||||
}
|
||||
return foundElement;
|
||||
}
|
||||
public findOneAndRemoveSync(findFunction: IObjectmapFindFunctionSync<T>): T {
|
||||
const foundElement = this.findSync(findFunction);
|
||||
if (foundElement) {
|
||||
this.remove(foundElement);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user