add new method Objectmap.getArray()
This commit is contained in:
parent
30e23a77b7
commit
924058c90a
4
dist/lik.objectmap.d.ts
vendored
4
dist/lik.objectmap.d.ts
vendored
@ -41,4 +41,8 @@ export declare class Objectmap<T> {
|
||||
* wipe Objectmap
|
||||
*/
|
||||
wipe(): void;
|
||||
/**
|
||||
* returns a cloned array of all the objects currently in the Objectmap
|
||||
*/
|
||||
getArray(): T[];
|
||||
}
|
||||
|
9
dist/lik.objectmap.js
vendored
9
dist/lik.objectmap.js
vendored
@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
const plugins = require("./lik.plugins");
|
||||
/**
|
||||
* allows keeping track of objects
|
||||
*/
|
||||
@ -65,6 +66,12 @@ class Objectmap {
|
||||
wipe() {
|
||||
this.objectArray = [];
|
||||
}
|
||||
/**
|
||||
* returns a cloned array of all the objects currently in the Objectmap
|
||||
*/
|
||||
getArray() {
|
||||
return plugins.lodash.cloneDeep(this.objectArray);
|
||||
}
|
||||
}
|
||||
exports.Objectmap = Objectmap;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQVVBOztHQUVHO0FBQ0g7SUFHSTs7T0FFRztJQUNIO1FBTFEsZ0JBQVcsR0FBUSxFQUFFLENBQUE7SUFPN0IsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFNBQVk7UUFDWixJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNwQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRLENBQUMsY0FBbUI7UUFDeEIsR0FBRyxDQUFDLENBQUMsSUFBSSxJQUFJLElBQUksY0FBYyxDQUFDLENBQUMsQ0FBQztZQUM5Qix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NKO0FBOUVELDhCQThFQyJ9
|
35
test/test.js
35
test/test.js
File diff suppressed because one or more lines are too long
33
test/test.ts
33
test/test.ts
@ -1,6 +1,7 @@
|
||||
import 'typings-test'
|
||||
import * as events from 'events'
|
||||
import * as rx from 'rxjs/Rx'
|
||||
import * as lodash from 'lodash'
|
||||
import * as should from 'should'
|
||||
|
||||
import lik = require('../dist/index')
|
||||
@ -13,14 +14,14 @@ describe('lik',function(){
|
||||
let testString4 = 'testString4'
|
||||
let testString5 = 'testString5'
|
||||
let testString6 = 'testString6'
|
||||
it('should create an instance of Stringmap',function(){
|
||||
it('new lik.Objectmap() -> should create an instance of Stringmap',function(){
|
||||
testStringmap = new lik.Stringmap()
|
||||
should(testStringmap).be.instanceof(lik.Stringmap)
|
||||
})
|
||||
it('should return false for an string not in Stringmap',function(){
|
||||
it('lik.Stringmap.checkString -> should return false for an string not in Stringmap',function(){
|
||||
should(testStringmap.checkString(testString1)).be.false()
|
||||
})
|
||||
it('should add an string to Stringmap',function(){
|
||||
it('lik.Stringmap.addString -> should add an string to Stringmap',function(){
|
||||
testStringmap.addString(testString1)
|
||||
testStringmap.addString(testString2)
|
||||
testStringmap.addString(testString3)
|
||||
@ -31,26 +32,26 @@ describe('lik',function(){
|
||||
should(testStringmap.checkMinimatch('*String2')).be.true()
|
||||
should(testStringmap.checkMinimatch('*String4')).be.false()
|
||||
})
|
||||
it('should add an array of strings',function(){
|
||||
it('lik.Stringmap.addStringArray -> should add an array of strings',function(){
|
||||
testStringmap.addStringArray([testString4,testString5,testString6])
|
||||
should(testStringmap.checkMinimatch('*String4')).be.true()
|
||||
})
|
||||
it('should remove a string from Stringmap',function(){
|
||||
it('lik.Stringmap.removeString -> should remove a string from Stringmap',function(){
|
||||
testStringmap.removeString(testString2)
|
||||
should(testStringmap.checkString(testString2)).be.false()
|
||||
})
|
||||
it('should return a copy of stringArray',function(){
|
||||
it('lik.Stringmap.getStringArray() -> should return a copy of stringArray',function(){
|
||||
let clonedArray = testStringmap.getStringArray()
|
||||
should(clonedArray[0] === 'testString1').be.true()
|
||||
should(clonedArray[0] === testString1).be.true()
|
||||
})
|
||||
it('should register a function to trigger when empty',function(){
|
||||
it('lik.Stringmap.checkIsEmpty() -> should register a function to trigger when empty',function(){
|
||||
testStringmap.registerUntilTrue(
|
||||
() => { return testStringmap.checkIsEmpty() },
|
||||
() => { console.log('Stringmap now is empty') }
|
||||
)
|
||||
})
|
||||
it('should remove wipe and then notify',function(){
|
||||
it('lik.Stringmap.empty() -> should remove wipe and then notify',function(){
|
||||
testStringmap.wipe()
|
||||
})
|
||||
})
|
||||
@ -68,32 +69,38 @@ describe('lik',function(){
|
||||
propOne: 'hello',
|
||||
propTwo: 'hello2'
|
||||
}
|
||||
it('should correctly instantiate an Objectmap',function(){
|
||||
it('new lik.Objectmap() -> should correctly instantiate an Objectmap',function(){
|
||||
testObjectmap = new lik.Objectmap<ITestObject>()
|
||||
should(testObjectmap).be.instanceof(lik.Objectmap)
|
||||
})
|
||||
it('should correctly add an object to Objectmap',function(){
|
||||
it('lik.Objectmap.add() -> should correctly add an object to Objectmap',function(){
|
||||
testObjectmap.add(testObject1)
|
||||
should(testObjectmap.checkForObject(testObject1)).be.true
|
||||
should(testObjectmap.checkForObject(testObject2)).be.false
|
||||
})
|
||||
it('should correctly remove an object to Objectmap',function(){
|
||||
it('lik.Objectmap.remove() -> should correctly remove an object to Objectmap',function(){
|
||||
testObjectmap.add(testObject2)
|
||||
testObjectmap.remove(testObject1)
|
||||
should(testObjectmap.checkForObject(testObject1)).be.false
|
||||
should(testObjectmap.checkForObject(testObject2)).be.true
|
||||
})
|
||||
it('should correctly run a function forEach map object',function(){
|
||||
it('Objectmap.forEach -> should correctly run a function forEach map object',function(){
|
||||
testObjectmap.forEach(itemArg => {
|
||||
should(itemArg).have.ownProperty('propOne')
|
||||
})
|
||||
})
|
||||
it('should correctly find an object',function(){
|
||||
it('lik.Objectmap.find() -> should correctly find an object',function(){
|
||||
let myObject = {propOne: 'helloThere', propTwo: 'helloAnyway'}
|
||||
testObjectmap.add(myObject)
|
||||
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.propOne === 'helloThere') })
|
||||
should(myObject === referenceObject).be.true()
|
||||
})
|
||||
it('lik.Objectmap.getArray() -> should return a cloned array', function(){
|
||||
let myObject = {propOne : 'test1', propTwo: 'wow, how awesome'}
|
||||
testObjectmap.add(myObject)
|
||||
let clonedArray = testObjectmap.getArray()
|
||||
should(lodash.isEqual(clonedArray[clonedArray.length - 1],myObject)).be.true()
|
||||
})
|
||||
})
|
||||
describe('Observablemap',function(){
|
||||
let testObservablemap: lik.Observablemap
|
||||
|
@ -82,4 +82,11 @@ export class Objectmap<T> {
|
||||
wipe() {
|
||||
this.objectArray = []
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a cloned array of all the objects currently in the Objectmap
|
||||
*/
|
||||
getArray() {
|
||||
return plugins.lodash.cloneDeep(this.objectArray)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user