fix(core): update

This commit is contained in:
Philipp Kunz 2020-07-14 10:55:48 +00:00
parent fa91e67aef
commit 298904e17e
2 changed files with 11 additions and 5 deletions

View File

@ -2,12 +2,13 @@ import * as plugins from './lik.plugins';
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap'; import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
export interface IInterestOptions { export interface IInterestOptions<DTInterestFullfillment> {
markLostAfterDefault: number; markLostAfterDefault: number;
defaultFullfillment?: DTInterestFullfillment;
} }
export class Interest<DTInterestId, DTInterestFullfillment> { export class Interest<DTInterestId, DTInterestFullfillment> {
public options: IInterestOptions; public options: IInterestOptions<DTInterestFullfillment>;
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>; private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
public originalInterest: DTInterestId; public originalInterest: DTInterestId;
@ -48,7 +49,7 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>, interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
interestArg: DTInterestId, interestArg: DTInterestId,
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>, comparisonFuncArg: IInterestComparisonFunc<DTInterestId>,
optionsArg?: IInterestOptions optionsArg?: IInterestOptions<DTInterestFullfillment>
) { ) {
this.interestMapRef = interestMapArg; this.interestMapRef = interestMapArg;
this.originalInterest = interestArg; this.originalInterest = interestArg;
@ -72,6 +73,9 @@ export class Interest<DTInterestId, DTInterestFullfillment> {
*/ */
public destroy() { public destroy() {
this.interestMapRef.removeInterest(this); this.interestMapRef.removeInterest(this);
if (!this.isFullfilled && this.options.defaultFullfillment) {
this.fullfillInterest(this.options.defaultFullfillment);
}
} }
/** /**

View File

@ -34,7 +34,8 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
* @param objectArg * @param objectArg
*/ */
public async addInterest( public async addInterest(
objectArg: DTInterestId objectArg: DTInterestId,
defaultFullfillmentArg?: DTInterestFullfillment
): Promise<Interest<DTInterestId, DTInterestFullfillment>> { ): Promise<Interest<DTInterestId, DTInterestFullfillment>> {
const comparisonString = this.comparisonFunc(objectArg); const comparisonString = this.comparisonFunc(objectArg);
let returnInterest: Interest<DTInterestId, DTInterestFullfillment>; let returnInterest: Interest<DTInterestId, DTInterestFullfillment>;
@ -43,7 +44,8 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
objectArg, objectArg,
this.comparisonFunc, this.comparisonFunc,
{ {
markLostAfterDefault: this.options.markLostAfterDefault markLostAfterDefault: this.options.markLostAfterDefault,
defaultFullfillment: defaultFullfillmentArg
} }
); );
let interestExists = false; let interestExists = false;