Compare commits

..

4 Commits

Author SHA1 Message Date
f84822dd5d 4.0.21 2021-09-12 15:39:47 +02:00
21d6e19a22 fix(core): update 2021-09-12 15:39:47 +02:00
8947738dc1 4.0.20 2020-11-24 19:11:43 +00:00
14bc5dcd25 fix(core): update 2020-11-24 19:11:42 +00:00
4 changed files with 30 additions and 12 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/lik",
"version": "4.0.19",
"version": "4.0.21",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/lik",
"version": "4.0.19",
"version": "4.0.21",
"private": false,
"description": "light little helpers for node",
"main": "dist_ts/index.js",

View File

@ -29,7 +29,7 @@ export class FastMap<T> {
return this.mapObject[keyArg];
}
public removeFromMap(keyArg): T {
public removeFromMap(keyArg: string): T {
const removedItem = this.getByKey(keyArg);
delete this.mapObject[keyArg];
return removedItem;
@ -50,7 +50,7 @@ export class FastMap<T> {
}
/**
* returns a new Objectmap that includes
* returns a new Fastmap that includes all values from this and all from the fastmap in the argument
*/
public concat(fastMapArg: FastMap<T>) {
const concatedFastmap = new FastMap<T>();
@ -68,9 +68,9 @@ export class FastMap<T> {
}
/**
* tries to merge another Objectmap
* tries to merge another Fastmap
* Note: uniqueKeyCollisions will cause overwrite
* @param objectMapArg
* @param fastMapArg
*/
public addAllFromOther(fastMapArg: FastMap<T>) {
for (const key of fastMapArg.getKeys()) {
@ -79,4 +79,10 @@ export class FastMap<T> {
});
}
}
public async find(findFunction: (mapItemArg: T) => Promise<boolean>) {
for (const key of this.getKeys()) {
}
}
}

View File

@ -17,6 +17,11 @@ export interface IObjectmapFindFunction<T> {
(itemArg: T): boolean;
}
export interface IObjectMapEventData<T> {
operation: 'add' | 'remove';
payload: T;
}
/**
* allows keeping track of objects
*/
@ -24,7 +29,7 @@ export class ObjectMap<T> {
private fastMap = new FastMap<T>();
// events
public eventSubject = new plugins.smartrx.rxjs.Subject<any>();
public eventSubject = new plugins.smartrx.rxjs.Subject<IObjectMapEventData<T>>();
/**
* returns a new instance
@ -57,8 +62,6 @@ export class ObjectMap<T> {
const object = this.getMappedUnique(uniqueKey);
}
public addSubject = new plugins.smartrx.rxjs.Subject<T>();
/**
* add object to Objectmap
* returns false if the object is already in the map
@ -76,7 +79,10 @@ export class ObjectMap<T> {
// otherwise lets create it
const uniqueKey = uni('key');
this.addMappedUnique(uniqueKey, objectArg);
this.addSubject.next(objectArg);
this.eventSubject.next({
operation: 'add',
payload: objectArg
});
return uniqueKey;
}
@ -153,7 +159,10 @@ export class ObjectMap<T> {
} else {
const keyToUse = keys[0];
const removedItem = this.fastMap.removeFromMap(keyToUse);
this.eventSubject.next('remove');
this.eventSubject.next({
operation: 'remove',
payload: removedItem
});
return removedItem;
}
}
@ -183,7 +192,10 @@ export class ObjectMap<T> {
if (this.checkForObject(objectArg)) {
const keyArg = this.getKeyForObject(objectArg);
const removedObject = this.fastMap.removeFromMap(keyArg);
this.eventSubject.next('remove');
this.eventSubject.next({
operation: 'remove',
payload: removedObject
});
return removedObject;
}
return null;