Compare commits

..

4 Commits

Author SHA1 Message Date
ccd5b80d67 4.0.17 2020-07-14 10:55:49 +00:00
298904e17e fix(core): update 2020-07-14 10:55:48 +00:00
fa91e67aef 4.0.16 2020-07-14 08:58:30 +00:00
5e99066bee fix(core): update 2020-07-14 08:58:30 +00:00
5 changed files with 14 additions and 7 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/lik", "name": "@pushrocks/lik",
"version": "4.0.15", "version": "4.0.17",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/lik", "name": "@pushrocks/lik",
"version": "4.0.15", "version": "4.0.17",
"private": false, "private": false,
"description": "light little helpers for node", "description": "light little helpers for node",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -1,5 +1,6 @@
export * from './lik.fastmap'; export * from './lik.fastmap';
export * from './lik.interestmap'; export * from './lik.interestmap';
export * from './lik.interestmap.interest';
export * from './lik.limitedarray'; export * from './lik.limitedarray';
export * from './lik.looptracker'; export * from './lik.looptracker';
export * from './lik.objectmap'; export * from './lik.objectmap';

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;