Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
42b59c109d | |||
8f18faaf1c | |||
ccd5b80d67 | |||
298904e17e | |||
fa91e67aef | |||
5e99066bee |
3216
package-lock.json
generated
3216
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
18
package.json
18
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/lik",
|
"name": "@pushrocks/lik",
|
||||||
"version": "4.0.15",
|
"version": "4.0.18",
|
||||||
"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",
|
||||||
@ -20,21 +20,21 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsbundle": "^1.0.72",
|
"@gitzone/tsbundle": "^1.0.78",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.41",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^14.0.22",
|
"@types/node": "^14.14.9",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.10",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
"@pushrocks/smartmatch": "^1.0.7",
|
"@pushrocks/smartmatch": "^1.0.7",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartrx": "^2.0.17",
|
"@pushrocks/smartrx": "^2.0.19",
|
||||||
"@pushrocks/smarttime": "^3.0.24",
|
"@pushrocks/smarttime": "^3.0.37",
|
||||||
"@types/minimatch": "^3.0.3",
|
"@types/minimatch": "^3.0.3",
|
||||||
"symbol-tree": "^3.2.4"
|
"symbol-tree": "^3.2.4"
|
||||||
},
|
},
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
// import test framework
|
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as events from 'events';
|
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
|
||||||
|
|
||||||
// import the module
|
|
||||||
import * as lik from '../ts/index';
|
|
||||||
|
|
||||||
// Objectmap
|
|
||||||
interface ITestObject {
|
|
||||||
propOne: string;
|
|
||||||
propTwo: string;
|
|
||||||
}
|
|
||||||
let testObjectmap: lik.ObjectMap<ITestObject>;
|
|
||||||
let testObject1: ITestObject = {
|
|
||||||
propOne: 'hello',
|
|
||||||
propTwo: 'hello2',
|
|
||||||
};
|
|
||||||
let testObject2: ITestObject = {
|
|
||||||
propOne: 'hello',
|
|
||||||
propTwo: 'hello2',
|
|
||||||
};
|
|
||||||
|
|
||||||
tap.test('new lik.Objectmap() -> should correctly instantiate an Objectmap', async () => {
|
|
||||||
testObjectmap = new lik.ObjectMap<ITestObject>();
|
|
||||||
expect(testObjectmap).be.instanceof(lik.ObjectMap);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('lik.Objectmap.add() -> should correctly add an object to Objectmap', async () => {
|
|
||||||
testObjectmap.add(testObject1);
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(testObjectmap.checkForObject(testObject1)).be.true;
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(testObjectmap.checkForObject(testObject2)).be.false;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('lik.Objectmap.remove() -> should correctly remove an object to Objectmap', async () => {
|
|
||||||
testObjectmap.add(testObject2);
|
|
||||||
testObjectmap.remove(testObject1);
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(testObjectmap.checkForObject(testObject1)).be.false;
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(testObjectmap.checkForObject(testObject2)).be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('Objectmap.forEach -> should correctly run a function forEach map object', async () => {
|
|
||||||
testObjectmap.forEach((itemArg) => {
|
|
||||||
expect(itemArg).to.have.property('propOne');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
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) => {
|
|
||||||
return itemArg.propOne === 'helloThere';
|
|
||||||
});
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(myObject === referenceObject).be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('lik.Objectmap.getArray() -> should return a cloned array', async () => {
|
|
||||||
let myObject = { propOne: 'test1', propTwo: 'wow, how awesome' };
|
|
||||||
testObjectmap.add(myObject);
|
|
||||||
let clonedArray = testObjectmap.getArray();
|
|
||||||
expect(clonedArray[clonedArray.length - 1]).to.eql(myObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should get one object and then remove it', async () => {
|
|
||||||
let originalLength = testObjectmap.getArray().length;
|
|
||||||
let oneObject = testObjectmap.getOneAndRemove();
|
|
||||||
// tslint:disable-next-line:no-unused-expression
|
|
||||||
expect(oneObject).not.be.null;
|
|
||||||
expect(testObjectmap.getArray().length).equal(originalLength - 1);
|
|
||||||
expect(testObjectmap.getArray()).to.not.contain(oneObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
@ -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';
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
|
@ -57,6 +57,8 @@ export class ObjectMap<T> {
|
|||||||
const object = this.getMappedUnique(uniqueKey);
|
const object = this.getMappedUnique(uniqueKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addSubject = new plugins.smartrx.rxjs.Subject<T>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add object to Objectmap
|
* add object to Objectmap
|
||||||
* returns false if the object is already in the map
|
* returns false if the object is already in the map
|
||||||
@ -74,6 +76,7 @@ export class ObjectMap<T> {
|
|||||||
// otherwise lets create it
|
// otherwise lets create it
|
||||||
const uniqueKey = uni('key');
|
const uniqueKey = uni('key');
|
||||||
this.addMappedUnique(uniqueKey, objectArg);
|
this.addMappedUnique(uniqueKey, objectArg);
|
||||||
|
this.addSubject.next(objectArg);
|
||||||
return uniqueKey;
|
return uniqueKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user