lik/ts/lik.objectmap.ts

53 lines
1.0 KiB
TypeScript
Raw Normal View History

2016-07-30 22:54:46 +00:00
import * as plugins from "./lik.plugins";
2016-07-31 12:36:28 +00:00
export interface IObjectmapForEach {
(itemArg):void
}
2016-07-30 22:54:46 +00:00
/**
* allows keeping track of objects
*/
export class Objectmap {
private objectArray = [];
2016-07-31 12:36:28 +00:00
/**
* add object to Objectmap
*/
2016-07-30 22:54:46 +00:00
add(objectArg){
this.objectArray.push(objectArg);
};
2016-07-31 12:36:28 +00:00
/**
* remove object from Objectmap
*/
2016-07-30 22:54:46 +00:00
remove(objectArg){
let replacmentArray = [];
for(let item of this.objectArray){
if(item !== objectArg){
replacmentArray.push(item);
}
};
this.objectArray = replacmentArray;
};
2016-07-31 12:36:28 +00:00
/**
* check if object is in Objectmap
*/
2016-07-30 22:54:46 +00:00
checkForObject(objectArg){
return this.objectArray.indexOf(objectArg !== -1)
};
2016-07-31 12:36:28 +00:00
/**
* run function for each item in Objectmap
*/
forEach(functionArg:IObjectmapForEach){
this.objectArray.forEach(functionArg);
}
/**
* wipe Objectmap
*/
2016-07-30 22:54:46 +00:00
wipe(){
this.objectArray = [];
}
}