diff --git a/dist/index.d.ts b/dist/index.d.ts index e10d5f8..6775686 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,3 +1,4 @@ -export * from './lik.stringmap'; +export * from './lik.looptracker'; export * from './lik.objectmap'; export * from './lik.observablemap'; +export * from './lik.stringmap'; diff --git a/dist/index.js b/dist/index.js index 2011208..2ee714a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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 \ No newline at end of file +__export(require("./lik.stringmap")); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUVBLGlCQUFpQjtBQUVqQix1Q0FBaUM7QUFDakMscUNBQStCO0FBQy9CLHlDQUFtQztBQUNuQyxxQ0FBK0IifQ== \ No newline at end of file diff --git a/dist/lik.looptracker.d.ts b/dist/lik.looptracker.d.ts new file mode 100644 index 0000000..107a5b5 --- /dev/null +++ b/dist/lik.looptracker.d.ts @@ -0,0 +1,10 @@ +import { Objectmap } from './lik.objectmap'; +export declare class LoopTracker { + referenceObjectMap: Objectmap; + constructor(); + /** + * checks and tracks an object + * @param objectArg + */ + checkAndTrack(objectArg: T): boolean; +} diff --git a/dist/lik.looptracker.js b/dist/lik.looptracker.js new file mode 100644 index 0000000..1108f93 --- /dev/null +++ b/dist/lik.looptracker.js @@ -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 \ No newline at end of file diff --git a/dist/lik.objectmap.d.ts b/dist/lik.objectmap.d.ts index 4e542be..82a1ac0 100644 --- a/dist/lik.objectmap.d.ts +++ b/dist/lik.objectmap.d.ts @@ -15,8 +15,10 @@ export declare class Objectmap { 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 */ diff --git a/dist/lik.objectmap.js b/dist/lik.objectmap.js index 21eab87..330bfb1 100644 --- a/dist/lik.objectmap.js +++ b/dist/lik.objectmap.js @@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBd0M7QUFVeEM7O0dBRUc7QUFDSDtJQUdFOztPQUVHO0lBQ0g7UUFMUSxnQkFBVyxHQUFRLEVBQUUsQ0FBQTtRQU0zQixlQUFlO0lBQ2pCLENBQUM7SUFFRDs7T0FFRztJQUNILEdBQUcsQ0FBRSxTQUFZO1FBQ2YsSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDbEMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsUUFBUSxDQUFFLGNBQW1CO1FBQzNCLEdBQUcsQ0FBQyxDQUFDLElBQUksSUFBSSxJQUFJLGNBQWMsQ0FBQyxDQUFDLENBQUM7WUFDaEMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUNoQixDQUFDO0lBQ0gsQ0FBQztJQUVEOztPQUVHO0lBQ0gsY0FBYyxDQUFFLFNBQVk7UUFDMUIsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFBO0lBQ25ELENBQUM7SUFFRDs7T0FFRztJQUNILElBQUksQ0FBRSxZQUF1QztRQU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QUN6QixHQUFHLENBQUMsQ0FBQyxJQUFJLElBQUksSUFBSSxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNsQyxFQUFFLENBQUMsQ0FBQyxJQUFJLEtBQUssU0FBUyxDQUFDLENBQUMsQ0FBQztnQkFDdkIsZ0JBQWdCLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO1lBQzdCLENBQUM7UUFDSCxDQUFDO1FBQ0QsSUFBSSxDQUFDLFdBQVcsR0FBRyxnQkFBZ0IsQ0FBQTtJQUNyQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJO1FBQ0YsSUFBSSxDQUFDLFdBQVcsR0FBRyxFQUFFLENBQUE7SUFDdkIsQ0FBQztDQUNGO0FBcEhELDhCQW9IQyJ9 \ No newline at end of file diff --git a/npmextra.json b/npmextra.json index 33dee61..0382c12 100644 --- a/npmextra.json +++ b/npmextra.json @@ -5,6 +5,9 @@ ] }, "npmts": { - "coverageTreshold": 40 + "coverageTreshold": 40, + "testConfig": { + "parallel": false + } } } \ No newline at end of file diff --git a/test/test.looptracker.ts b/test/test.looptracker.ts new file mode 100644 index 0000000..c07ea6c --- /dev/null +++ b/test/test.looptracker.ts @@ -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 + +// tests +tap.test('should create a valid looptracker instance', async () => { + myLoopTracker = new lik.LoopTracker() + expect(myLoopTracker).to.be.instanceof(lik.LoopTracker) +}) diff --git a/test/test.objectmap.ts b/test/test.objectmap.ts new file mode 100644 index 0000000..58bbab8 --- /dev/null +++ b/test/test.objectmap.ts @@ -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 +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() + 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() diff --git a/test/test.observablemap.ts b/test/test.observablemap.ts new file mode 100644 index 0000000..b062cd8 --- /dev/null +++ b/test/test.observablemap.ts @@ -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 +let testObservable2: rx.Observable +let testObservable3: rx.Observable +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() diff --git a/test/test.stringmap.ts b/test/test.stringmap.ts new file mode 100644 index 0000000..a05f989 --- /dev/null +++ b/test/test.stringmap.ts @@ -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() diff --git a/test/test.ts b/test/test.ts deleted file mode 100644 index 97e878b..0000000 --- a/test/test.ts +++ /dev/null @@ -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 -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() - 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 -let testObservable2: rx.Observable -let testObservable3: rx.Observable -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() diff --git a/ts/index.ts b/ts/index.ts index 52bef47..a5427b7 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -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' diff --git a/ts/lik.looptracker.ts b/ts/lik.looptracker.ts new file mode 100644 index 0000000..ee4d9b1 --- /dev/null +++ b/ts/lik.looptracker.ts @@ -0,0 +1,18 @@ +import * as plugins from './lik.plugins' + +import { Objectmap } from './lik.objectmap' + +export class LoopTracker { + referenceObjectMap = new Objectmap() + constructor () { + // nothing here + } + + /** + * checks and tracks an object + * @param objectArg + */ + checkAndTrack (objectArg: T) { + return this.referenceObjectMap.add(objectArg) + } +} diff --git a/ts/lik.objectmap.ts b/ts/lik.objectmap.ts index 33c9a9d..05906a6 100644 --- a/ts/lik.objectmap.ts +++ b/ts/lik.objectmap.ts @@ -23,9 +23,18 @@ export 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: 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 + } } /** diff --git a/ts/lik.plugins.ts b/ts/lik.plugins.ts index 767a57d..cfcbdaf 100644 --- a/ts/lik.plugins.ts +++ b/ts/lik.plugins.ts @@ -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 { - lift(operator: Operator): Observable; + lift(operator: Operator): Observable } }