add loop tracker
This commit is contained in:
parent
217252de1e
commit
281cfdc38a
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,3 +1,4 @@
|
||||
export * from './lik.stringmap';
|
||||
export * from './lik.looptracker';
|
||||
export * from './lik.objectmap';
|
||||
export * from './lik.observablemap';
|
||||
export * from './lik.stringmap';
|
||||
|
5
dist/index.js
vendored
5
dist/index.js
vendored
@ -4,7 +4,8 @@ function __export(m) {
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// import modules
|
||||
__export(require("./lik.stringmap"));
|
||||
__export(require("./lik.looptracker"));
|
||||
__export(require("./lik.objectmap"));
|
||||
__export(require("./lik.observablemap"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLGlCQUFpQjtBQUVqQixxQ0FBK0I7QUFDL0IscUNBQStCO0FBQy9CLHlDQUFtQyJ9
|
||||
__export(require("./lik.stringmap"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLGlCQUFpQjtBQUVqQix1Q0FBaUM7QUFDakMscUNBQStCO0FBQy9CLHlDQUFtQztBQUNuQyxxQ0FBK0IifQ==
|
10
dist/lik.looptracker.d.ts
vendored
Normal file
10
dist/lik.looptracker.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { Objectmap } from './lik.objectmap';
|
||||
export declare class LoopTracker<T> {
|
||||
referenceObjectMap: Objectmap<any>;
|
||||
constructor();
|
||||
/**
|
||||
* checks and tracks an object
|
||||
* @param objectArg
|
||||
*/
|
||||
checkAndTrack(objectArg: T): boolean;
|
||||
}
|
18
dist/lik.looptracker.js
vendored
Normal file
18
dist/lik.looptracker.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const lik_objectmap_1 = require("./lik.objectmap");
|
||||
class LoopTracker {
|
||||
constructor() {
|
||||
this.referenceObjectMap = new lik_objectmap_1.Objectmap();
|
||||
// nothing here
|
||||
}
|
||||
/**
|
||||
* checks and tracks an object
|
||||
* @param objectArg
|
||||
*/
|
||||
checkAndTrack(objectArg) {
|
||||
return this.referenceObjectMap.add(objectArg);
|
||||
}
|
||||
}
|
||||
exports.LoopTracker = LoopTracker;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLmxvb3B0cmFja2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbGlrLmxvb3B0cmFja2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUEsbURBQTJDO0FBRTNDO0lBRUU7UUFEQSx1QkFBa0IsR0FBRyxJQUFJLHlCQUFTLEVBQU8sQ0FBQTtRQUV2QyxlQUFlO0lBQ2pCLENBQUM7SUFFRDs7O09BR0c7SUFDSCxhQUFhLENBQUUsU0FBWTtRQUN6QixNQUFNLENBQUMsSUFBSSxDQUFDLGtCQUFrQixDQUFDLEdBQUcsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUMvQyxDQUFDO0NBQ0Y7QUFiRCxrQ0FhQyJ9
|
4
dist/lik.objectmap.d.ts
vendored
4
dist/lik.objectmap.d.ts
vendored
@ -15,8 +15,10 @@ export declare class Objectmap<T> {
|
||||
constructor();
|
||||
/**
|
||||
* add object to Objectmap
|
||||
* returns false if the object is already in the map
|
||||
* returns true if the object was added successfully
|
||||
*/
|
||||
add(objectArg: T): void;
|
||||
add(objectArg: T): boolean;
|
||||
/**
|
||||
* like .add but adds an whole array of objects
|
||||
*/
|
||||
|
14
dist/lik.objectmap.js
vendored
14
dist/lik.objectmap.js
vendored
@ -14,9 +14,19 @@ class Objectmap {
|
||||
}
|
||||
/**
|
||||
* add object to Objectmap
|
||||
* returns false if the object is already in the map
|
||||
* returns true if the object was added successfully
|
||||
*/
|
||||
add(objectArg) {
|
||||
this.objectArray.push(objectArg);
|
||||
if (this.checkForObject(objectArg)) {
|
||||
// the object is already in the objectmap
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// the object is not yet in the objectmap
|
||||
this.objectArray.push(objectArg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* like .add but adds an whole array of objects
|
||||
@ -103,4 +113,4 @@ class Objectmap {
|
||||
}
|
||||
}
|
||||
exports.Objectmap = Objectmap;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBd0M7QUFVeEM7O0dBRUc7QUFDSDtJQUdFOztPQUVHO0lBQ0g7UUFMUSxnQkFBVyxHQUFRLEVBQUUsQ0FBQTtRQU0zQixlQUFlO0lBQ2pCLENBQUM7SUFFRDs7T0FFRztJQUNILEdBQUcsQ0FBRSxTQUFZO1FBQ2YsSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDbEMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsUUFBUSxDQUFFLGNBQW1CO1FBQzNCLEdBQUcsQ0FBQyxDQUFDLElBQUksSUFBSSxJQUFJLGNBQWMsQ0FBQyxDQUFDLENBQUM7WUFDaEMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQU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ztZQUNsQyxNQUFNLENBQUMsSUFBSSxDQUFBO1FBQ2IsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ04sTUFBTSxDQUFDLEtBQUssQ0FBQTtRQUNkLENBQUM7SUFDSCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxNQUFNLENBQUUsU0FBWTtRQUNsQixJQUFJLGdCQUFnQixHQUFHLEVBQUUsQ0FBQTtRQUN6QixHQUFHLENBQUMsQ0FBQyxJQUFJLElBQUksSUFBSSxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNsQyxFQUFFLENBQUMsQ0FBQyxJQUFJLEtBQUssU0FBUyxDQUFDLENBQUMsQ0FBQztnQkFDdkIsZ0JBQWdCLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO1lBQzdCLENBQUM7UUFDSCxDQUFDO1FBQ0QsSUFBSSxDQUFDLFdBQVcsR0FBRyxnQkFBZ0IsQ0FBQTtJQUNyQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJO1FBQ0YsSUFBSSxDQUFDLFdBQVcsR0FBRyxFQUFFLENBQUE7SUFDdkIsQ0FBQztDQUNGO0FBcEhELDhCQW9IQyJ9
|
@ -5,6 +5,9 @@
|
||||
]
|
||||
},
|
||||
"npmts": {
|
||||
"coverageTreshold": 40
|
||||
"coverageTreshold": 40,
|
||||
"testConfig": {
|
||||
"parallel": false
|
||||
}
|
||||
}
|
||||
}
|
18
test/test.looptracker.ts
Normal file
18
test/test.looptracker.ts
Normal file
@ -0,0 +1,18 @@
|
||||
// import test framework
|
||||
import { expect, tap } from 'tapbundle'
|
||||
import * as events from 'events'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
import * as smartq from 'smartq'
|
||||
|
||||
// import the module
|
||||
import lik = require('../dist/index')
|
||||
|
||||
let object1 = {}
|
||||
let object2 = {}
|
||||
let myLoopTracker: lik.LoopTracker<any>
|
||||
|
||||
// tests
|
||||
tap.test('should create a valid looptracker instance', async () => {
|
||||
myLoopTracker = new lik.LoopTracker()
|
||||
expect(myLoopTracker).to.be.instanceof(lik.LoopTracker)
|
||||
})
|
77
test/test.objectmap.ts
Normal file
77
test/test.objectmap.ts
Normal file
@ -0,0 +1,77 @@
|
||||
// import test framework
|
||||
import { expect, tap } from 'tapbundle'
|
||||
import * as events from 'events'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
import * as smartq from 'smartq'
|
||||
|
||||
// import the module
|
||||
import lik = require('../dist/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).have.ownProperty('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 ]).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()
|
38
test/test.observablemap.ts
Normal file
38
test/test.observablemap.ts
Normal file
@ -0,0 +1,38 @@
|
||||
// import test framework
|
||||
import { expect, tap } from 'tapbundle'
|
||||
import * as events from 'events'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
import * as smartq from 'smartq'
|
||||
|
||||
// import the module
|
||||
import lik = require('../dist/index')
|
||||
|
||||
let testObservablemap: lik.Observablemap
|
||||
let testObservable1: rx.Observable<any>
|
||||
let testObservable2: rx.Observable<any>
|
||||
let testObservable3: rx.Observable<any>
|
||||
let testEmitter: events.EventEmitter
|
||||
|
||||
tap.test('should create an instance', async () => {
|
||||
testObservablemap = new lik.Observablemap()
|
||||
expect(testObservablemap).be.instanceof(lik.Observablemap)
|
||||
})
|
||||
|
||||
tap.test('should accept a new emitter', async () => {
|
||||
let done = smartq.defer()
|
||||
testEmitter = new events.EventEmitter()
|
||||
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
|
||||
testObservable1.subscribe(x => {
|
||||
done.resolve()
|
||||
})
|
||||
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
|
||||
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2')
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testObservable1 === testObservable2).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testObservable1 === testObservable3).be.false
|
||||
testEmitter.emit('event1')
|
||||
await done.promise
|
||||
})
|
||||
|
||||
tap.start()
|
79
test/test.stringmap.ts
Normal file
79
test/test.stringmap.ts
Normal file
@ -0,0 +1,79 @@
|
||||
// import test framework
|
||||
import { expect, tap } from 'tapbundle'
|
||||
import * as events from 'events'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
import * as smartq from 'smartq'
|
||||
|
||||
// import the module
|
||||
import lik = require('../dist/index')
|
||||
|
||||
// testData
|
||||
let testStringmap: lik.Stringmap
|
||||
let testString1 = 'testString1'
|
||||
let testString2 = 'testString2'
|
||||
let testString3 = 'testString3'
|
||||
let testString4 = 'testString4'
|
||||
let testString5 = 'testString5'
|
||||
let testString6 = 'testString6'
|
||||
|
||||
// tests
|
||||
tap.test('new lik.Objectmap() -> should create an instance of Stringmap', async () => {
|
||||
testStringmap = new lik.Stringmap()
|
||||
expect(testStringmap).be.instanceof(lik.Stringmap)
|
||||
})
|
||||
|
||||
tap.test('lik.Stringmap.checkString -> should return false for an string not in Stringmap', async () => {
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString1)).be.false
|
||||
})
|
||||
|
||||
tap.test('lik.Stringmap.addString -> should add an string to Stringmap', async () => {
|
||||
testStringmap.addString(testString1)
|
||||
testStringmap.addString(testString2)
|
||||
testStringmap.addString(testString3)
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString1)).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString2)).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString3)).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String1')).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String2')).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String4')).be.false
|
||||
})
|
||||
|
||||
tap.test('lik.Stringmap.addStringArray -> should add an array of strings', async () => {
|
||||
testStringmap.addStringArray([ testString4, testString5, testString6 ])
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String4')).be.true
|
||||
})
|
||||
|
||||
tap.test('lik.Stringmap.removeString -> should remove a string from Stringmap', async () => {
|
||||
testStringmap.removeString(testString2)
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString2)).be.false
|
||||
})
|
||||
|
||||
tap.test('lik.Stringmap.getStringArray() -> should return a copy of stringArray', async () => {
|
||||
let clonedArray = testStringmap.getStringArray()
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(clonedArray[ 0 ] === 'testString1').be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(clonedArray[ 0 ] === testString1).be.true
|
||||
})
|
||||
|
||||
tap.test('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty', async () => {
|
||||
testStringmap.registerUntilTrue(
|
||||
() => { return testStringmap.checkIsEmpty() },
|
||||
() => { console.log('Stringmap now is empty') }
|
||||
)
|
||||
})
|
||||
|
||||
tap.test('lik.Stringmap.empty() -> should remove wipe and then notify', async () => {
|
||||
testStringmap.wipe()
|
||||
})
|
||||
|
||||
tap.start()
|
151
test/test.ts
151
test/test.ts
@ -1,151 +0,0 @@
|
||||
import { expect, tap } from 'tapbundle'
|
||||
import * as events from 'events'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
import * as smartq from 'smartq'
|
||||
|
||||
import lik = require('../dist/index')
|
||||
let testStringmap: lik.Stringmap
|
||||
let testString1 = 'testString1'
|
||||
let testString2 = 'testString2'
|
||||
let testString3 = 'testString3'
|
||||
let testString4 = 'testString4'
|
||||
let testString5 = 'testString5'
|
||||
let testString6 = 'testString6'
|
||||
tap.test('new lik.Objectmap() -> should create an instance of Stringmap', async () => {
|
||||
testStringmap = new lik.Stringmap()
|
||||
expect(testStringmap).be.instanceof(lik.Stringmap)
|
||||
})
|
||||
tap.test('lik.Stringmap.checkString -> should return false for an string not in Stringmap', async () => {
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString1)).be.false
|
||||
})
|
||||
tap.test('lik.Stringmap.addString -> should add an string to Stringmap', async () => {
|
||||
testStringmap.addString(testString1)
|
||||
testStringmap.addString(testString2)
|
||||
testStringmap.addString(testString3)
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString1)).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString2)).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString3)).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String1')).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String2')).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String4')).be.false
|
||||
})
|
||||
tap.test('lik.Stringmap.addStringArray -> should add an array of strings', async () => {
|
||||
testStringmap.addStringArray([ testString4, testString5, testString6 ])
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkMinimatch('*String4')).be.true
|
||||
})
|
||||
tap.test('lik.Stringmap.removeString -> should remove a string from Stringmap', async () => {
|
||||
testStringmap.removeString(testString2)
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testStringmap.checkString(testString2)).be.false
|
||||
})
|
||||
tap.test('lik.Stringmap.getStringArray() -> should return a copy of stringArray', async () => {
|
||||
let clonedArray = testStringmap.getStringArray()
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(clonedArray[ 0 ] === 'testString1').be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(clonedArray[ 0 ] === testString1).be.true
|
||||
})
|
||||
tap.test('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty', async () => {
|
||||
testStringmap.registerUntilTrue(
|
||||
() => { return testStringmap.checkIsEmpty() },
|
||||
() => { console.log('Stringmap now is empty') }
|
||||
)
|
||||
})
|
||||
tap.test('lik.Stringmap.empty() -> should remove wipe and then notify', async () => {
|
||||
testStringmap.wipe()
|
||||
})
|
||||
|
||||
// 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).have.ownProperty('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 ]).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)
|
||||
})
|
||||
let testObservablemap: lik.Observablemap
|
||||
let testObservable1: rx.Observable<any>
|
||||
let testObservable2: rx.Observable<any>
|
||||
let testObservable3: rx.Observable<any>
|
||||
let testEmitter: events.EventEmitter
|
||||
tap.test('should create an instance', async () => {
|
||||
testObservablemap = new lik.Observablemap()
|
||||
expect(testObservablemap).be.instanceof(lik.Observablemap)
|
||||
})
|
||||
tap.test('should accept a new emitter', async () => {
|
||||
let done = smartq.defer()
|
||||
testEmitter = new events.EventEmitter()
|
||||
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
|
||||
testObservable1.subscribe(x => {
|
||||
done.resolve()
|
||||
})
|
||||
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
|
||||
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2')
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testObservable1 === testObservable2).be.true
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testObservable1 === testObservable3).be.false
|
||||
testEmitter.emit('event1')
|
||||
await done.promise
|
||||
})
|
||||
|
||||
tap.start()
|
@ -2,6 +2,7 @@ import * as plugins from './lik.plugins'
|
||||
|
||||
// import modules
|
||||
|
||||
export * from './lik.stringmap'
|
||||
export * from './lik.looptracker'
|
||||
export * from './lik.objectmap'
|
||||
export * from './lik.observablemap'
|
||||
export * from './lik.stringmap'
|
||||
|
18
ts/lik.looptracker.ts
Normal file
18
ts/lik.looptracker.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import * as plugins from './lik.plugins'
|
||||
|
||||
import { Objectmap } from './lik.objectmap'
|
||||
|
||||
export class LoopTracker<T> {
|
||||
referenceObjectMap = new Objectmap<any>()
|
||||
constructor () {
|
||||
// nothing here
|
||||
}
|
||||
|
||||
/**
|
||||
* checks and tracks an object
|
||||
* @param objectArg
|
||||
*/
|
||||
checkAndTrack (objectArg: T) {
|
||||
return this.referenceObjectMap.add(objectArg)
|
||||
}
|
||||
}
|
@ -23,9 +23,18 @@ export class Objectmap<T> {
|
||||
|
||||
/**
|
||||
* add object to Objectmap
|
||||
* returns false if the object is already in the map
|
||||
* returns true if the object was added successfully
|
||||
*/
|
||||
add (objectArg: T) {
|
||||
this.objectArray.push(objectArg)
|
||||
add (objectArg: T): boolean {
|
||||
if (this.checkForObject(objectArg)) {
|
||||
// the object is already in the objectmap
|
||||
return false
|
||||
} else {
|
||||
// the object is not yet in the objectmap
|
||||
this.objectArray.push(objectArg)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,10 +6,10 @@ export import minimatch = require('minimatch')
|
||||
export import rx = require('rxjs/Rx')
|
||||
|
||||
// workaround
|
||||
import {Operator} from 'rxjs/Operator';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Operator} from 'rxjs/Operator'
|
||||
import {Observable} from 'rxjs/Observable'
|
||||
declare module 'rxjs/Subject' {
|
||||
interface Subject<T> {
|
||||
lift<R>(operator: Operator<T, R>): Observable<R>;
|
||||
lift<R>(operator: Operator<T, R>): Observable<R>
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user