add getOneAndRemove and findOneAndRemove
This commit is contained in:
parent
59173eebc4
commit
afad357ed0
20
dist/lik.objectmap.d.ts
vendored
20
dist/lik.objectmap.d.ts
vendored
@ -21,10 +21,6 @@ export declare class Objectmap<T> {
|
|||||||
* like .add but adds an whole array of objects
|
* like .add but adds an whole array of objects
|
||||||
*/
|
*/
|
||||||
addArray(objectArrayArg: T[]): void;
|
addArray(objectArrayArg: T[]): void;
|
||||||
/**
|
|
||||||
* remove object from Objectmap
|
|
||||||
*/
|
|
||||||
remove(objectArg: T): void;
|
|
||||||
/**
|
/**
|
||||||
* check if object is in Objectmap
|
* check if object is in Objectmap
|
||||||
*/
|
*/
|
||||||
@ -38,11 +34,23 @@ export declare class Objectmap<T> {
|
|||||||
*/
|
*/
|
||||||
forEach(functionArg: IObjectmapForEachFunction<T>): void;
|
forEach(functionArg: IObjectmapForEachFunction<T>): void;
|
||||||
/**
|
/**
|
||||||
* wipe Objectmap
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
||||||
*/
|
*/
|
||||||
wipe(): void;
|
getOneAndRemove(): T;
|
||||||
|
/**
|
||||||
|
* finds a specific element and then removes it
|
||||||
|
*/
|
||||||
|
findOneAndRemove(findFunction: any): T;
|
||||||
/**
|
/**
|
||||||
* returns a cloned array of all the objects currently in the Objectmap
|
* returns a cloned array of all the objects currently in the Objectmap
|
||||||
*/
|
*/
|
||||||
getArray(): T[];
|
getArray(): T[];
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg: T): void;
|
||||||
|
/**
|
||||||
|
* wipe Objectmap
|
||||||
|
*/
|
||||||
|
wipe(): void;
|
||||||
}
|
}
|
||||||
|
48
dist/lik.objectmap.js
vendored
48
dist/lik.objectmap.js
vendored
@ -24,18 +24,6 @@ class Objectmap {
|
|||||||
this.add(item);
|
this.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* remove object from Objectmap
|
|
||||||
*/
|
|
||||||
remove(objectArg) {
|
|
||||||
let replacmentArray = [];
|
|
||||||
for (let item of this.objectArray) {
|
|
||||||
if (item !== objectArg) {
|
|
||||||
replacmentArray.push(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.objectArray = replacmentArray;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* check if object is in Objectmap
|
* check if object is in Objectmap
|
||||||
*/
|
*/
|
||||||
@ -61,10 +49,20 @@ class Objectmap {
|
|||||||
return this.objectArray.forEach(functionArg);
|
return this.objectArray.forEach(functionArg);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* wipe Objectmap
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
||||||
*/
|
*/
|
||||||
wipe() {
|
getOneAndRemove() {
|
||||||
this.objectArray = [];
|
return this.objectArray.shift();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* finds a specific element and then removes it
|
||||||
|
*/
|
||||||
|
findOneAndRemove(findFunction) {
|
||||||
|
let foundElement = this.find(findFunction);
|
||||||
|
if (foundElement) {
|
||||||
|
this.remove(foundElement);
|
||||||
|
}
|
||||||
|
return foundElement;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* returns a cloned array of all the objects currently in the Objectmap
|
* returns a cloned array of all the objects currently in the Objectmap
|
||||||
@ -72,6 +70,24 @@ class Objectmap {
|
|||||||
getArray() {
|
getArray() {
|
||||||
return plugins.lodash.cloneDeep(this.objectArray);
|
return plugins.lodash.cloneDeep(this.objectArray);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg) {
|
||||||
|
let replacementArray = [];
|
||||||
|
for (let item of this.objectArray) {
|
||||||
|
if (item !== objectArg) {
|
||||||
|
replacementArray.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.objectArray = replacementArray;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* wipe Objectmap
|
||||||
|
*/
|
||||||
|
wipe() {
|
||||||
|
this.objectArray = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.Objectmap = Objectmap;
|
exports.Objectmap = Objectmap;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHlDQUF3QztBQVV4Qzs7R0FFRztBQUNIO0lBR0k7O09BRUc7SUFDSDtRQUxRLGdCQUFXLEdBQVEsRUFBRSxDQUFBO0lBTzdCLENBQUM7SUFFRDs7T0FFRztJQUNILEdBQUcsQ0FBQyxTQUFZO1FBQ1osSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDcEMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsUUFBUSxDQUFDLGNBQW1CO1FBQ3hCLEdBQUcsQ0FBQyxDQUFDLElBQUksSUFBSSxJQUFJLGNBQWMsQ0FBQyxDQUFDLENBQUM7WUFDOUIsSUFBSSxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsQ0FBQTtRQUNsQixDQUFDO0lBQ0wsQ0FBQztJQUVEOztPQUVHO0lBQ0gsTUFBTSxDQUFDLFNBQVk7UUFDZixJQUFJLGVBQWUsR0FBRyxFQUFFLENBQUE7UUFDeEIsR0FBRyxDQUFDLENBQUMsSUFBSSxJQUFJLElBQUksSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFDLENBQUM7WUFDaEMsRUFBRSxDQUFDLENBQUMsSUFBSSxLQUFLLFNBQVMsQ0FBQyxDQUFDLENBQUM7Z0JBQ3JCLGVBQWUsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUE7WUFDOUIsQ0FBQztRQUNMLENBQUM7UUFDRCxJQUFJLENBQUMsV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LGdCQUFnQixDQUFBO0lBQ3ZDLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7UUFDQSxJQUFJLENBQUMsV0FBVyxHQUFHLEVBQUUsQ0FBQTtJQUN6QixDQUFDO0NBQ0o7QUFoR0QsOEJBZ0dDIn0=
|
7
dist/lik.observablemap.d.ts
vendored
7
dist/lik.observablemap.d.ts
vendored
@ -10,7 +10,14 @@ export interface ObservableEmitterBundle {
|
|||||||
emitter: plugins.events.EventEmitter;
|
emitter: plugins.events.EventEmitter;
|
||||||
event: string;
|
event: string;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* manages observables by making sure that only one observable is regsitered per event
|
||||||
|
*/
|
||||||
export declare class Observablemap {
|
export declare class Observablemap {
|
||||||
ObservableEmitterBundleObjectmap: Objectmap<ObservableEmitterBundle>;
|
ObservableEmitterBundleObjectmap: Objectmap<ObservableEmitterBundle>;
|
||||||
|
/**
|
||||||
|
* creates a new observable if not yet registered for the same event.
|
||||||
|
* In case event has been registered before the same observable is returned.
|
||||||
|
*/
|
||||||
getObservableForEmitterEvent(emitterArg: plugins.events.EventEmitter, eventArg: string): Observable<any>;
|
getObservableForEmitterEvent(emitterArg: plugins.events.EventEmitter, eventArg: string): Observable<any>;
|
||||||
}
|
}
|
||||||
|
9
dist/lik.observablemap.js
vendored
9
dist/lik.observablemap.js
vendored
@ -1,10 +1,17 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const plugins = require("./lik.plugins");
|
const plugins = require("./lik.plugins");
|
||||||
const lik_objectmap_1 = require("./lik.objectmap");
|
const lik_objectmap_1 = require("./lik.objectmap");
|
||||||
|
/**
|
||||||
|
* manages observables by making sure that only one observable is regsitered per event
|
||||||
|
*/
|
||||||
class Observablemap {
|
class Observablemap {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ObservableEmitterBundleObjectmap = new lik_objectmap_1.Objectmap();
|
this.ObservableEmitterBundleObjectmap = new lik_objectmap_1.Objectmap();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* creates a new observable if not yet registered for the same event.
|
||||||
|
* In case event has been registered before the same observable is returned.
|
||||||
|
*/
|
||||||
getObservableForEmitterEvent(emitterArg, eventArg) {
|
getObservableForEmitterEvent(emitterArg, eventArg) {
|
||||||
let existingBundle = this.ObservableEmitterBundleObjectmap.find((bundleArg) => {
|
let existingBundle = this.ObservableEmitterBundleObjectmap.find((bundleArg) => {
|
||||||
return (bundleArg.emitter === emitterArg && bundleArg.event === eventArg);
|
return (bundleArg.emitter === emitterArg && bundleArg.event === eventArg);
|
||||||
@ -24,4 +31,4 @@ class Observablemap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Observablemap = Observablemap;
|
exports.Observablemap = Observablemap;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9ic2VydmFibGVtYXAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9saWsub2JzZXJ2YWJsZW1hcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEseUNBQXdDO0FBQ3hDLG1EQUEyQztBQWMzQztJQUFBO1FBQ0kscUNBQWdDLEdBQUcsSUFBSSx5QkFBUyxFQUEyQixDQUFBO0lBa0IvRSxDQUFDO0lBaEJHLDRCQUE0QixDQUFDLFVBQXVDLEVBQUUsUUFBZ0I7UUFDbEYsSUFBSSxjQUFjLEdBQUcsSUFBSSxDQUFDLGdDQUFnQyxDQUFDLElBQUksQ0FBQyxDQUFDLFNBQVM7WUFDdEUsTUFBTSxDQUFBLENBQUMsU0FBUyxDQUFDLE9BQU8sS0FBSyxVQUFVLElBQUksU0FBUyxDQUFDLEtBQUssS0FBSyxRQUFRLENBQUMsQ0FBQTtRQUM1RSxDQUFDLENBQUMsQ0FBQTtRQUNGLEVBQUUsQ0FBQyxDQUFDLGNBQWMsQ0FBQyxDQUFDLENBQUM7WUFDakIsTUFBTSxDQUFDLGNBQWMsQ0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BRSxDQUFDLENBQUMsY0FBYyxDQUFDLENBQUMsQ0FBQztZQUNqQixNQUFNLENBQUMsY0FBYyxDQUFDLFVBQVUsQ0FBQTtRQUNwQyxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixJQUFJLGlCQUFpQixHQUFHLE9BQU8sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFNBQVMsQ0FBQyxVQUFVLEVBQUUsUUFBUSxDQUFDLENBQUE7WUFDN0UsSUFBSSxDQUFDLGdDQUFnQyxDQUFDLEdBQUcsQ0FBQztnQkFDdEMsVUFBVSxFQUFFLGlCQUFpQjtnQkFDN0IsT0FBTyxFQUFFLFVBQVU7Z0JBQ25CLEtBQUssRUFBRSxRQUFRO2FBQ2xCLENBQUMsQ0FBQTtZQUNGLE1BQU0sQ0FBQyxpQkFBaUIsQ0FBQTtRQUM1QixDQUFDO0lBQ0wsQ0FBQztDQUNKO0FBdkJELHNDQXVCQyJ9
|
12
test/test.js
12
test/test.js
File diff suppressed because one or more lines are too long
10
test/test.ts
10
test/test.ts
@ -1,7 +1,6 @@
|
|||||||
import 'typings-test'
|
import 'typings-test'
|
||||||
import * as events from 'events'
|
import * as events from 'events'
|
||||||
import * as rx from 'rxjs/Rx'
|
import * as rx from 'rxjs/Rx'
|
||||||
import * as lodash from 'lodash'
|
|
||||||
import * as should from 'should'
|
import * as should from 'should'
|
||||||
|
|
||||||
import lik = require('../dist/index')
|
import lik = require('../dist/index')
|
||||||
@ -99,7 +98,14 @@ describe('lik',function(){
|
|||||||
let myObject = {propOne : 'test1', propTwo: 'wow, how awesome'}
|
let myObject = {propOne : 'test1', propTwo: 'wow, how awesome'}
|
||||||
testObjectmap.add(myObject)
|
testObjectmap.add(myObject)
|
||||||
let clonedArray = testObjectmap.getArray()
|
let clonedArray = testObjectmap.getArray()
|
||||||
should(lodash.isEqual(clonedArray[clonedArray.length - 1],myObject)).be.true()
|
should(clonedArray[clonedArray.length - 1]).eql(myObject)
|
||||||
|
})
|
||||||
|
it('should get one object and then remove it', function() {
|
||||||
|
let originalLength = testObjectmap.getArray().length
|
||||||
|
let oneObject = testObjectmap.getOneAndRemove()
|
||||||
|
should(oneObject).not.be.null()
|
||||||
|
should(testObjectmap.getArray().length).equal(originalLength - 1)
|
||||||
|
should(testObjectmap.getArray()).not.containEql(oneObject)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('Observablemap',function(){
|
describe('Observablemap',function(){
|
||||||
|
@ -37,19 +37,6 @@ export class Objectmap<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* remove object from Objectmap
|
|
||||||
*/
|
|
||||||
remove(objectArg: T) {
|
|
||||||
let replacmentArray = []
|
|
||||||
for (let item of this.objectArray) {
|
|
||||||
if (item !== objectArg) {
|
|
||||||
replacmentArray.push(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.objectArray = replacmentArray
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if object is in Objectmap
|
* check if object is in Objectmap
|
||||||
*/
|
*/
|
||||||
@ -77,10 +64,21 @@ export class Objectmap<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wipe Objectmap
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
||||||
*/
|
*/
|
||||||
wipe() {
|
getOneAndRemove() {
|
||||||
this.objectArray = []
|
return this.objectArray.shift()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* finds a specific element and then removes it
|
||||||
|
*/
|
||||||
|
findOneAndRemove(findFunction) {
|
||||||
|
let foundElement = this.find(findFunction)
|
||||||
|
if (foundElement) {
|
||||||
|
this.remove(foundElement)
|
||||||
|
}
|
||||||
|
return foundElement
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,4 +87,24 @@ export class Objectmap<T> {
|
|||||||
getArray() {
|
getArray() {
|
||||||
return plugins.lodash.cloneDeep(this.objectArray)
|
return plugins.lodash.cloneDeep(this.objectArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove object from Objectmap
|
||||||
|
*/
|
||||||
|
remove(objectArg: T) {
|
||||||
|
let replacementArray = []
|
||||||
|
for (let item of this.objectArray) {
|
||||||
|
if (item !== objectArg) {
|
||||||
|
replacementArray.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.objectArray = replacementArray
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wipe Objectmap
|
||||||
|
*/
|
||||||
|
wipe() {
|
||||||
|
this.objectArray = []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,16 @@ export interface ObservableEmitterBundle {
|
|||||||
event: string
|
event: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manages observables by making sure that only one observable is regsitered per event
|
||||||
|
*/
|
||||||
export class Observablemap {
|
export class Observablemap {
|
||||||
ObservableEmitterBundleObjectmap = new Objectmap<ObservableEmitterBundle>()
|
ObservableEmitterBundleObjectmap = new Objectmap<ObservableEmitterBundle>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a new observable if not yet registered for the same event.
|
||||||
|
* In case event has been registered before the same observable is returned.
|
||||||
|
*/
|
||||||
getObservableForEmitterEvent(emitterArg: plugins.events.EventEmitter, eventArg: string) {
|
getObservableForEmitterEvent(emitterArg: plugins.events.EventEmitter, eventArg: string) {
|
||||||
let existingBundle = this.ObservableEmitterBundleObjectmap.find((bundleArg) => {
|
let existingBundle = this.ObservableEmitterBundleObjectmap.find((bundleArg) => {
|
||||||
return(bundleArg.emitter === emitterArg && bundleArg.event === eventArg)
|
return(bundleArg.emitter === emitterArg && bundleArg.event === eventArg)
|
||||||
|
Loading…
Reference in New Issue
Block a user