Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
8d660a8573 | |||
596a897afc | |||
e1442b1bc8 | |||
2ca9e14f76 | |||
e65f36dfa2 | |||
adb95cd683 | |||
d2106690b4 | |||
2ea5111eb8 | |||
aae10344fe | |||
52b65d7dc3 | |||
1135b418cb | |||
2eb1dbd0b3 | |||
8ec54c17a1 | |||
500a291b2a | |||
256a14fcb0 | |||
7aa0f05bae | |||
6208cab36a | |||
50a9697baf | |||
7956cf6ace | |||
d8956d4e32 | |||
c93a67c351 | |||
fafd9867ad | |||
2dfa96bbc5 | |||
a7484e791a | |||
2dba68df8c | |||
6aff4c9031 |
25
.gitignore
vendored
25
.gitignore
vendored
@ -1,5 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
pages/
|
|
||||||
public/
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
.nogit/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
133
.gitlab-ci.yml
133
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,108 +18,103 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g snyk
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- priv
|
||||||
testSTABLE:
|
|
||||||
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci node install stable
|
||||||
- npmci npm test
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g npmpage
|
- npmci node install lts
|
||||||
- npmci command npmpage
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -127,15 +122,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
windowsCompatibility:
|
|
||||||
image: stefanscherer/node-windows:10-build-tools
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npm install & npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- windows
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
47
README.md
47
README.md
@ -1,47 +0,0 @@
|
|||||||
# lik
|
|
||||||
|
|
||||||
light little helpers for node
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/lik)
|
|
||||||
[](https://GitLab.com/pushrocks/lik)
|
|
||||||
[](https://github.com/pushrocks/lik)
|
|
||||||
[](https://pushrocks.gitlab.io/lik/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/lik/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/lik/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/lik)
|
|
||||||
[](https://david-dm.org/pushrocks/lik)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/lik/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/lik)
|
|
||||||
[](https://snyk.io/test/npm/lik)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// import any tool that you need from lik
|
|
||||||
import { Stringmap, Objectmap, Observablemap } from 'lik';
|
|
||||||
```
|
|
||||||
|
|
||||||
### class Stringmap
|
|
||||||
|
|
||||||
Stringmap allows you to keep track of strings. It allows you to register triggers for certain events
|
|
||||||
like when a certain string is removed or added to the map
|
|
||||||
|
|
||||||
### class Objectmap
|
|
||||||
|
|
||||||
Sometimes you need to keep track of objects, but implementing logic for removing, finding or updating is tedious.
|
|
||||||
Objectmap takes care of keeping track of objects for you.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"@gitzone/npmts"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"npmts": {
|
"gitzone": {
|
||||||
"coverageTreshold": 40,
|
"projectType": "npm",
|
||||||
"testConfig": {
|
"module": {
|
||||||
"parallel": false
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "lik",
|
||||||
|
"shortDescription": "light little helpers for node",
|
||||||
|
"npmPackagename": "@pushrocks/lik",
|
||||||
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1791
package-lock.json
generated
1791
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/lik",
|
"name": "@pushrocks/lik",
|
||||||
"version": "3.0.1",
|
"version": "3.0.14",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "light little helpers for node",
|
"description": "light little helpers for node",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tsrun test/test.ts",
|
"test": "(tstest test/)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -20,16 +20,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
"homepage": "https://gitlab.com/pushrocks/lik#README",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.1.9",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@pushrocks/tapbundle": "^3.0.1",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@types/node": "^10.5.2"
|
"@gitzone/tstest": "^1.0.28",
|
||||||
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
|
"@types/node": "^13.7.0",
|
||||||
|
"tslint": "^6.0.0",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartdelay": "^2.0.6",
|
||||||
"@types/lodash": "^4.14.112",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
|
"@pushrocks/smartrx": "^2.0.5",
|
||||||
|
"@pushrocks/smarttime": "^3.0.12",
|
||||||
"@types/minimatch": "^3.0.3",
|
"@types/minimatch": "^3.0.3",
|
||||||
"lodash": "^4.17.10",
|
|
||||||
"minimatch": "^3.0.4",
|
"minimatch": "^3.0.4",
|
||||||
"symbol-tree": "^3.2.2"
|
"symbol-tree": "^3.2.4"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_web/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
25
test/test.interestmap.ts
Normal file
25
test/test.interestmap.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
import * as lik from '../ts/index';
|
||||||
|
|
||||||
|
let testInterestmap: lik.InterestMap<number, number>;
|
||||||
|
|
||||||
|
tap.test('should create an interestmap', async () => {
|
||||||
|
testInterestmap = new lik.InterestMap(numberArg => {
|
||||||
|
return numberArg.toString();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create an interest', async () => {
|
||||||
|
testInterestmap.addInterest(3);
|
||||||
|
testInterestmap.addInterest(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should return an already existing interest', async () => {
|
||||||
|
await testInterestmap.addInterest(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should be able to inform about a lost interest', async () => {
|
||||||
|
testInterestmap.informLostInterest(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -1,7 +1,7 @@
|
|||||||
// import test framework
|
// import test framework
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as events from 'events';
|
import * as events from 'events';
|
||||||
import * as smartq from 'smartq';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
// import the module
|
// import the module
|
||||||
import * as lik from '../ts/index';
|
import * as lik from '../ts/index';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// import test framework
|
// import test framework
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as events from 'events';
|
import * as events from 'events';
|
||||||
import * as smartq from 'smartq';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
// import the module
|
// import the module
|
||||||
import * as lik from '../ts/index';
|
import * as lik from '../ts/index';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// import test framework
|
// import test framework
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as events from 'events';
|
import * as events from 'events';
|
||||||
import * as smartq from 'smartq';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
// import the module
|
// import the module
|
||||||
import * as lik from '../ts/index';
|
import * as lik from '../ts/index';
|
||||||
|
25
test/test.timedaggregator.ts
Normal file
25
test/test.timedaggregator.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// import test framework
|
||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as events from 'events';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
|
// import the module
|
||||||
|
import * as lik from '../ts/index';
|
||||||
|
|
||||||
|
let testTimedAggregator: lik.TimedAggregtor<string>;
|
||||||
|
|
||||||
|
tap.test('should create a timed aggregaotor', async tools => {
|
||||||
|
testTimedAggregator = new lik.TimedAggregtor<string>({
|
||||||
|
aggregationIntervalInMillis: 1000,
|
||||||
|
functionForAggregation: aggregation => {
|
||||||
|
console.log(aggregation);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
testTimedAggregator.add('This');
|
||||||
|
testTimedAggregator.add('is a whole sentence.');
|
||||||
|
await tools.delayFor(1001);
|
||||||
|
testTimedAggregator.add('This one is another.');
|
||||||
|
await tools.delayFor(2000);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -1,14 +1,20 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import * as lik from '../ts/index';
|
import * as lik from '../ts/index';
|
||||||
|
|
||||||
let testTree = new lik.Tree<TestClass>();
|
|
||||||
|
|
||||||
class TestClass {
|
class TestClass {
|
||||||
constructor(public hey: string) {
|
constructor(public hey: string) {
|
||||||
// nothing here
|
// nothing here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let testTree = new lik.Tree<TestClass>();
|
||||||
|
|
||||||
let testInstance = new TestClass('first');
|
let testInstance = new TestClass('first');
|
||||||
|
let testInstance2 = new TestClass('second');
|
||||||
|
let testInstance3 = new TestClass('third');
|
||||||
|
let testInstance4 = new TestClass('fourth');
|
||||||
|
let testInstance5 = new TestClass('fifth');
|
||||||
|
let testInstance6 = new TestClass('sixth');
|
||||||
|
|
||||||
tap.test('create a valid tree instance', async () => {
|
tap.test('create a valid tree instance', async () => {
|
||||||
testTree = new lik.Tree();
|
testTree = new lik.Tree();
|
||||||
@ -21,4 +27,14 @@ tap.test('should insert an object', async () => {
|
|||||||
expect(resultArray).to.contain(testInstance);
|
expect(resultArray).to.contain(testInstance);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should add other objects in a hierachy', async () => {
|
||||||
|
testTree.appendChild(testInstance, testInstance2);
|
||||||
|
testTree.appendChild(testInstance, testInstance3);
|
||||||
|
testTree.appendChild(testInstance, testInstance4);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test("should create a JSON object that reflects a tree's hierachy", async () => {
|
||||||
|
const jsonTreet = testTree.toJsonWithHierachy(testInstance);
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -2,8 +2,10 @@ import * as plugins from './lik.plugins';
|
|||||||
|
|
||||||
// import modules
|
// import modules
|
||||||
|
|
||||||
|
export * from './lik.interestmap';
|
||||||
|
export * from './lik.limitedarray';
|
||||||
export * from './lik.looptracker';
|
export * from './lik.looptracker';
|
||||||
export * from './lik.objectmap';
|
export * from './lik.objectmap';
|
||||||
export * from './lik.stringmap';
|
export * from './lik.stringmap';
|
||||||
export * from './lik.limitedarray';
|
export * from './lik.timedaggregator';
|
||||||
export * from './lik.tree';
|
export * from './lik.tree';
|
||||||
|
11
ts/lik.fastmap.ts
Normal file
11
ts/lik.fastmap.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as plugins from './lik.plugins';
|
||||||
|
|
||||||
|
export class FastMap<T> {
|
||||||
|
private mapObject: { [key: string]: T } = {};
|
||||||
|
|
||||||
|
public isUniqueKey() {}
|
||||||
|
|
||||||
|
public addToMap(identifier: string, objectArg: T) {
|
||||||
|
this.mapObject[identifier] = objectArg;
|
||||||
|
}
|
||||||
|
}
|
78
ts/lik.interestmap.interest.ts
Normal file
78
ts/lik.interestmap.interest.ts
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
import * as plugins from './lik.plugins';
|
||||||
|
|
||||||
|
import { InterestMap, IInterestComparisonFunc } from './lik.interestmap';
|
||||||
|
|
||||||
|
export class Interest<DTInterestId, DTInterestFullfillment> {
|
||||||
|
private interestMapRef: InterestMap<DTInterestId, DTInterestFullfillment>;
|
||||||
|
public originalInterest: DTInterestId;
|
||||||
|
public comparisonFunc: IInterestComparisonFunc<DTInterestId>;
|
||||||
|
public destructionTimer = new plugins.smarttime.Timer(10000);
|
||||||
|
public isFullfilled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a generic store to store objects in that are needed for fullfillment;
|
||||||
|
*/
|
||||||
|
public fullfillmentStore: any[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* quick access to a string that makes the interest comparable for checking for similar interests
|
||||||
|
*/
|
||||||
|
public get comparisonString() {
|
||||||
|
return this.comparisonFunc(this.originalInterest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private interestDeferred: plugins.smartpromise.Deferred<
|
||||||
|
DTInterestFullfillment
|
||||||
|
> = new plugins.smartpromise.Deferred();
|
||||||
|
public interestFullfilled = this.interestDeferred.promise;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fullfill the interest
|
||||||
|
*/
|
||||||
|
public fullfillInterest(objectArg: DTInterestFullfillment) {
|
||||||
|
this.isFullfilled = true;
|
||||||
|
this.fullfillmentStore = [];
|
||||||
|
this.interestDeferred.resolve(objectArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
interestMapArg: InterestMap<DTInterestId, DTInterestFullfillment>,
|
||||||
|
interestArg: DTInterestId,
|
||||||
|
comparisonFuncArg: IInterestComparisonFunc<DTInterestId>
|
||||||
|
) {
|
||||||
|
this.originalInterest = interestArg;
|
||||||
|
this.comparisonFunc = comparisonFuncArg;
|
||||||
|
this.interestMapRef = interestMapArg;
|
||||||
|
this.destructionTimer.completed.then(() => {
|
||||||
|
this.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// LIFECYCLE MANAGEMENT
|
||||||
|
// ===============================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* self destructs the interest
|
||||||
|
*/
|
||||||
|
public destroy() {
|
||||||
|
this.interestMapRef.removeInterest(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notifies the interest that the interest in it has been lost
|
||||||
|
*/
|
||||||
|
public markLost() {
|
||||||
|
this.destructionTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notifies the interest that the interest in it has been restored
|
||||||
|
*/
|
||||||
|
public renew() {
|
||||||
|
this.destructionTimer.reset();
|
||||||
|
}
|
||||||
|
}
|
114
ts/lik.interestmap.ts
Normal file
114
ts/lik.interestmap.ts
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
import * as plugins from './lik.plugins';
|
||||||
|
import { Objectmap } from './lik.objectmap';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
import { Interest } from './lik.interestmap.interest';
|
||||||
|
|
||||||
|
export type IInterestComparisonFunc<T> = (objectArg: T) => string;
|
||||||
|
|
||||||
|
export class InterestMap<DTInterestId, DTInterestFullfillment> {
|
||||||
|
/**
|
||||||
|
* stores interests that are currently fullfilled by the cache
|
||||||
|
*/
|
||||||
|
private interestObjectMap = new Objectmap<Interest<DTInterestId, DTInterestFullfillment>>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a function to compare interests
|
||||||
|
*/
|
||||||
|
private comparisonFunc: IInterestComparisonFunc<DTInterestId>;
|
||||||
|
|
||||||
|
constructor(comparisonFuncArg: IInterestComparisonFunc<DTInterestId>) {
|
||||||
|
this.comparisonFunc = comparisonFuncArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds an interest to the InterestMap
|
||||||
|
* @param objectArg
|
||||||
|
*/
|
||||||
|
public async addInterest(
|
||||||
|
objectArg: DTInterestId
|
||||||
|
): Promise<Interest<DTInterestId, DTInterestFullfillment>> {
|
||||||
|
const comparisonString = this.comparisonFunc(objectArg);
|
||||||
|
let returnInterest: Interest<DTInterestId, DTInterestFullfillment>;
|
||||||
|
const newInterest = new Interest<DTInterestId, DTInterestFullfillment>(
|
||||||
|
this,
|
||||||
|
objectArg,
|
||||||
|
this.comparisonFunc
|
||||||
|
);
|
||||||
|
let interestExists = false;
|
||||||
|
await this.interestObjectMap.forEach(interestArg => {
|
||||||
|
if (!interestExists && interestArg.comparisonString === newInterest.comparisonString) {
|
||||||
|
console.log('info', `interest already exists for ${newInterest.comparisonString}`);
|
||||||
|
interestExists = true;
|
||||||
|
returnInterest = interestArg;
|
||||||
|
returnInterest.renew();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!returnInterest) {
|
||||||
|
returnInterest = newInterest;
|
||||||
|
this.interestObjectMap.add(returnInterest);
|
||||||
|
}
|
||||||
|
this.interestObservable.push(returnInterest);
|
||||||
|
return returnInterest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line:member-ordering
|
||||||
|
public interestObservable = new plugins.smartrx.ObservableIntake<Interest<DTInterestId, any>>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes an interest from the interest map
|
||||||
|
* @param objectArg removes an interest from the InterestMap
|
||||||
|
*/
|
||||||
|
public removeInterest(interestArg: Interest<DTInterestId, DTInterestFullfillment>) {
|
||||||
|
const interestToRemove = this.interestObjectMap.findOneAndRemove(interestArg2 => {
|
||||||
|
return interestArg.comparisonString === interestArg2.comparisonString;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check interest
|
||||||
|
*/
|
||||||
|
public checkInterest(objectArg: DTInterestId): boolean {
|
||||||
|
const comparisonString = this.comparisonFunc(objectArg);
|
||||||
|
return this.checkInterestByString(comparisonString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks an interest
|
||||||
|
* @param comparisonStringArg
|
||||||
|
*/
|
||||||
|
public checkInterestByString(comparisonStringArg: string): boolean {
|
||||||
|
const foundInterest = this.interestObjectMap.find(interest => {
|
||||||
|
return interest.comparisonString === comparisonStringArg;
|
||||||
|
});
|
||||||
|
if (foundInterest) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inform lost interest
|
||||||
|
* @param interestId
|
||||||
|
*/
|
||||||
|
public informLostInterest(interestId: DTInterestId) {
|
||||||
|
const wantedInterest = this.findInterest(interestId);
|
||||||
|
if (wantedInterest) {
|
||||||
|
wantedInterest.markLost();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* finds an interest
|
||||||
|
* @param objectArg
|
||||||
|
*/
|
||||||
|
public findInterest(objectArg: DTInterestId): Interest<DTInterestId, DTInterestFullfillment> {
|
||||||
|
const comparableString = this.comparisonFunc(objectArg);
|
||||||
|
const interest = this.interestObjectMap.find(interest => {
|
||||||
|
return interest.comparisonString === comparableString;
|
||||||
|
});
|
||||||
|
return interest; // if an interest is found, the interest is returned, otherwise interest is null
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './lik.plugins';
|
import * as plugins from './lik.plugins';
|
||||||
|
import { FastMap } from './lik.fastmap';
|
||||||
|
|
||||||
export interface IObjectmapForEachFunction<T> {
|
export interface IObjectmapForEachFunction<T> {
|
||||||
(itemArg: T): void;
|
(itemArg: T): void;
|
||||||
@ -12,8 +13,12 @@ export interface IObjectmapFindFunction<T> {
|
|||||||
* allows keeping track of objects
|
* allows keeping track of objects
|
||||||
*/
|
*/
|
||||||
export class Objectmap<T> {
|
export class Objectmap<T> {
|
||||||
|
private fastMap = new FastMap<T>();
|
||||||
private objectArray: T[] = [];
|
private objectArray: T[] = [];
|
||||||
|
|
||||||
|
// events
|
||||||
|
public eventSubject = new plugins.smartrx.rxjs.Subject<any>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a new instance
|
* returns a new instance
|
||||||
*/
|
*/
|
||||||
@ -21,18 +26,40 @@ export class Objectmap<T> {
|
|||||||
// nothing here
|
// nothing here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds an object mapped to a string
|
||||||
|
* the string must be unique
|
||||||
|
*/
|
||||||
|
addMappedUnique(uniqueKey: string, objectArg: T) {
|
||||||
|
this.add(objectArg);
|
||||||
|
this.fastMap.addToMap(uniqueKey, objectArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fastest way to get an object from the map
|
||||||
|
* @param uniqueKey
|
||||||
|
*/
|
||||||
|
public getMappedUnique(uniqueKey: string) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove key
|
||||||
|
* @param functionArg
|
||||||
|
*/
|
||||||
|
public removeMappedUnique() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add object to Objectmap
|
* add object to Objectmap
|
||||||
* returns false if the object is already in the map
|
* returns false if the object is already in the map
|
||||||
* returns true if the object was added successfully
|
* returns true if the object was added successfully
|
||||||
*/
|
*/
|
||||||
add(objectArg: T): boolean {
|
public add(objectArg: T): boolean {
|
||||||
if (this.checkForObject(objectArg)) {
|
if (this.checkForObject(objectArg)) {
|
||||||
// the object is already in the objectmap
|
// the object is already in the objectmap
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// the object is not yet in the objectmap
|
// the object is not yet in the objectmap
|
||||||
this.objectArray.push(objectArg);
|
this.objectArray.push(objectArg);
|
||||||
|
this.eventSubject.next('add');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +67,7 @@ export class Objectmap<T> {
|
|||||||
/**
|
/**
|
||||||
* like .add but adds an whole array of objects
|
* like .add but adds an whole array of objects
|
||||||
*/
|
*/
|
||||||
addArray(objectArrayArg: T[]) {
|
public addArray(objectArrayArg: T[]) {
|
||||||
for (let item of objectArrayArg) {
|
for (let item of objectArrayArg) {
|
||||||
this.add(item);
|
this.add(item);
|
||||||
}
|
}
|
||||||
@ -49,15 +76,15 @@ export class Objectmap<T> {
|
|||||||
/**
|
/**
|
||||||
* check if object is in Objectmap
|
* check if object is in Objectmap
|
||||||
*/
|
*/
|
||||||
checkForObject(objectArg: T) {
|
public checkForObject(objectArg: T) {
|
||||||
return this.objectArray.indexOf(objectArg) !== -1;
|
return this.objectArray.indexOf(objectArg) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find object
|
* find object
|
||||||
*/
|
*/
|
||||||
find(findFunction: IObjectmapFindFunction<T>) {
|
public find(findFunction: IObjectmapFindFunction<T>) {
|
||||||
let resultArray = this.objectArray.filter(findFunction);
|
const resultArray = this.objectArray.filter(findFunction);
|
||||||
if (resultArray.length > 0) {
|
if (resultArray.length > 0) {
|
||||||
return resultArray[0];
|
return resultArray[0];
|
||||||
} else {
|
} else {
|
||||||
@ -68,8 +95,8 @@ export class Objectmap<T> {
|
|||||||
/**
|
/**
|
||||||
* finds a specific element and then removes it
|
* finds a specific element and then removes it
|
||||||
*/
|
*/
|
||||||
findOneAndRemove(findFunction: IObjectmapFindFunction<T>): T {
|
public findOneAndRemove(findFunction: IObjectmapFindFunction<T>): T {
|
||||||
let foundElement = this.find(findFunction);
|
const foundElement = this.find(findFunction);
|
||||||
if (foundElement) {
|
if (foundElement) {
|
||||||
this.remove(foundElement);
|
this.remove(foundElement);
|
||||||
}
|
}
|
||||||
@ -79,7 +106,7 @@ export class Objectmap<T> {
|
|||||||
/**
|
/**
|
||||||
* run function for each item in Objectmap
|
* run function for each item in Objectmap
|
||||||
*/
|
*/
|
||||||
async forEach(functionArg: IObjectmapForEachFunction<T>) {
|
public async forEach(functionArg: IObjectmapForEachFunction<T>) {
|
||||||
for (let object of this.objectArray) {
|
for (let object of this.objectArray) {
|
||||||
await functionArg(object);
|
await functionArg(object);
|
||||||
}
|
}
|
||||||
@ -88,21 +115,27 @@ export class Objectmap<T> {
|
|||||||
/**
|
/**
|
||||||
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
* gets an object in the Observablemap and removes it, so it can't be retrieved again
|
||||||
*/
|
*/
|
||||||
getOneAndRemove(): T {
|
public getOneAndRemove(): T {
|
||||||
return this.objectArray.shift();
|
const removedItem = this.objectArray.shift();
|
||||||
|
this.eventSubject.next('remove');
|
||||||
|
return removedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
public getArray(): T[] {
|
||||||
return plugins.lodash.cloneDeep(this.objectArray);
|
const returnArray: any[] = [];
|
||||||
|
for (const objectItem of this.objectArray) {
|
||||||
|
returnArray.push(objectItem);
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if Objectmap ist empty
|
* check if Objectmap ist empty
|
||||||
*/
|
*/
|
||||||
isEmpty(): boolean {
|
public isEmpty(): boolean {
|
||||||
if (this.objectArray.length === 0) {
|
if (this.objectArray.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -113,7 +146,7 @@ export class Objectmap<T> {
|
|||||||
/**
|
/**
|
||||||
* remove object from Objectmap
|
* remove object from Objectmap
|
||||||
*/
|
*/
|
||||||
remove(objectArg: T) {
|
public remove(objectArg: T) {
|
||||||
let replacementArray = [];
|
let replacementArray = [];
|
||||||
for (let item of this.objectArray) {
|
for (let item of this.objectArray) {
|
||||||
if (item !== objectArg) {
|
if (item !== objectArg) {
|
||||||
@ -121,12 +154,14 @@ export class Objectmap<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.objectArray = replacementArray;
|
this.objectArray = replacementArray;
|
||||||
|
this.eventSubject.next('remove');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wipe Objectmap
|
* wipe Objectmap
|
||||||
*/
|
*/
|
||||||
wipe() {
|
public wipe() {
|
||||||
this.objectArray = [];
|
this.objectArray = [];
|
||||||
|
this.eventSubject.next('wiped');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,25 @@
|
|||||||
|
// ==============
|
||||||
|
// native
|
||||||
|
// ==============
|
||||||
|
|
||||||
import * as events from 'events';
|
import * as events from 'events';
|
||||||
import * as lodash from 'lodash';
|
|
||||||
import * as minimatch from 'minimatch';
|
export { events };
|
||||||
|
|
||||||
|
// ==============
|
||||||
|
// @pushrocks
|
||||||
|
// ==============
|
||||||
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
|
|
||||||
|
export { smartdelay, smartpromise, smartrx, smarttime };
|
||||||
|
|
||||||
|
// ==============
|
||||||
|
// third party
|
||||||
|
// ==============
|
||||||
|
import minimatch from 'minimatch';
|
||||||
const symbolTree = require('symbol-tree');
|
const symbolTree = require('symbol-tree');
|
||||||
|
|
||||||
export { events, lodash, minimatch, smartpromise, symbolTree };
|
export { minimatch, symbolTree };
|
||||||
|
@ -24,7 +24,7 @@ export class Stringmap {
|
|||||||
* like addString, but accepts an array of strings
|
* like addString, but accepts an array of strings
|
||||||
*/
|
*/
|
||||||
addStringArray(stringArrayArg: string[]) {
|
addStringArray(stringArrayArg: string[]) {
|
||||||
for (let stringItem of stringArrayArg) {
|
for (const stringItem of stringArrayArg) {
|
||||||
this.addString(stringItem);
|
this.addString(stringItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ export class Stringmap {
|
|||||||
* removes a string from Stringmap
|
* removes a string from Stringmap
|
||||||
*/
|
*/
|
||||||
removeString(stringArg: string) {
|
removeString(stringArg: string) {
|
||||||
for (let keyArg in this._stringArray) {
|
for (const keyArg in this._stringArray) {
|
||||||
if (this._stringArray[keyArg] === stringArg) {
|
if (this._stringArray[keyArg] === stringArg) {
|
||||||
this._stringArray.splice(parseInt(keyArg), 1);
|
this._stringArray.splice(parseInt(keyArg), 1);
|
||||||
}
|
}
|
||||||
@ -52,16 +52,16 @@ export class Stringmap {
|
|||||||
/**
|
/**
|
||||||
* check if string is in Stringmap
|
* check if string is in Stringmap
|
||||||
*/
|
*/
|
||||||
checkString(stringArg: string): boolean {
|
public checkString(stringArg: string): boolean {
|
||||||
return this._stringArray.indexOf(stringArg) !== -1;
|
return this._stringArray.indexOf(stringArg) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks stringPresence with minimatch
|
* checks stringPresence with minimatch
|
||||||
*/
|
*/
|
||||||
checkMinimatch(miniMatchStringArg: string): boolean {
|
public checkMinimatch(miniMatchStringArg: string): boolean {
|
||||||
let foundMatch: boolean = false;
|
let foundMatch: boolean = false;
|
||||||
for (let stringItem of this._stringArray) {
|
for (const stringItem of this._stringArray) {
|
||||||
if (plugins.minimatch(stringItem, miniMatchStringArg)) {
|
if (plugins.minimatch(stringItem, miniMatchStringArg)) {
|
||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
}
|
}
|
||||||
@ -72,15 +72,19 @@ export class Stringmap {
|
|||||||
/**
|
/**
|
||||||
* checks if the Stringmap is empty
|
* checks if the Stringmap is empty
|
||||||
*/
|
*/
|
||||||
checkIsEmpty() {
|
public checkIsEmpty() {
|
||||||
return this._stringArray.length === 0;
|
return this._stringArray.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets a cloned copy of the current string Array
|
* gets a cloned copy of the current string Array
|
||||||
*/
|
*/
|
||||||
getStringArray() {
|
public getStringArray() {
|
||||||
return plugins.lodash.cloneDeep(this._stringArray);
|
const returnArray: string[] = [];
|
||||||
|
for (const stringItem of this._stringArray) {
|
||||||
|
returnArray.push(stringItem);
|
||||||
|
}
|
||||||
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger registering
|
// trigger registering
|
||||||
@ -88,9 +92,9 @@ export class Stringmap {
|
|||||||
/**
|
/**
|
||||||
* register a new trigger
|
* register a new trigger
|
||||||
*/
|
*/
|
||||||
registerUntilTrue(functionArg: ITriggerFunction, doFunctionArg) {
|
public registerUntilTrue(functionArg: ITriggerFunction, doFunctionArg) {
|
||||||
this._triggerUntilTrueFunctionArray.push(() => {
|
this._triggerUntilTrueFunctionArray.push(() => {
|
||||||
let result = functionArg();
|
const result = functionArg();
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
doFunctionArg();
|
doFunctionArg();
|
||||||
}
|
}
|
||||||
@ -103,7 +107,7 @@ export class Stringmap {
|
|||||||
* notifies triggers
|
* notifies triggers
|
||||||
*/
|
*/
|
||||||
private notifyTrigger() {
|
private notifyTrigger() {
|
||||||
let filteredArray = this._triggerUntilTrueFunctionArray.filter(functionArg => {
|
const filteredArray = this._triggerUntilTrueFunctionArray.filter(functionArg => {
|
||||||
return !functionArg();
|
return !functionArg();
|
||||||
});
|
});
|
||||||
this._triggerUntilTrueFunctionArray = filteredArray;
|
this._triggerUntilTrueFunctionArray = filteredArray;
|
||||||
|
41
ts/lik.timedaggregator.ts
Normal file
41
ts/lik.timedaggregator.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import * as plugins from './lik.plugins';
|
||||||
|
|
||||||
|
export interface ITimedAggregatorOptions<T> {
|
||||||
|
aggregationIntervalInMillis: number;
|
||||||
|
functionForAggregation: (input: T[]) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TimedAggregtor<T> {
|
||||||
|
public options: ITimedAggregatorOptions<T>;
|
||||||
|
private storageArray: T[] = [];
|
||||||
|
|
||||||
|
constructor(optionsArg: ITimedAggregatorOptions<T>) {
|
||||||
|
this.options = optionsArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private aggregationTimer: plugins.smarttime.Timer;
|
||||||
|
private checkAggregationStatus() {
|
||||||
|
const addAggregationTimer = () => {
|
||||||
|
this.aggregationTimer = new plugins.smarttime.Timer(this.options.aggregationIntervalInMillis);
|
||||||
|
this.aggregationTimer.completed.then(() => {
|
||||||
|
const aggregateForProcessing = this.storageArray;
|
||||||
|
if (aggregateForProcessing.length === 0) {
|
||||||
|
this.aggregationTimer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.storageArray = [];
|
||||||
|
addAggregationTimer();
|
||||||
|
this.options.functionForAggregation(aggregateForProcessing);
|
||||||
|
});
|
||||||
|
this.aggregationTimer.start();
|
||||||
|
};
|
||||||
|
if (!this.aggregationTimer) {
|
||||||
|
addAggregationTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public add(aggregationArg: T) {
|
||||||
|
this.storageArray.push(aggregationArg);
|
||||||
|
this.checkAggregationStatus();
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,10 @@ export class Tree<T> {
|
|||||||
this.symbolTree = new plugins.symbolTree();
|
this.symbolTree = new plugins.symbolTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =======================================
|
||||||
|
// Functions that map to the functionality of symbol-tree
|
||||||
|
// =======================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param objectArg
|
* @param objectArg
|
||||||
@ -78,7 +82,7 @@ export class Tree<T> {
|
|||||||
this.symbolTree.ancestorsIterator();
|
this.symbolTree.ancestorsIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
treeIterator(rootArg: T, optionsArg): T {
|
treeIterator(rootArg: T, optionsArg): Iterable<T> {
|
||||||
return this.symbolTree.treeIterator(rootArg);
|
return this.symbolTree.treeIterator(rootArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,4 +117,25 @@ export class Tree<T> {
|
|||||||
appendChild(referenceObjectArg, newObjectArg) {
|
appendChild(referenceObjectArg, newObjectArg) {
|
||||||
return this.symbolTree.appendChild(referenceObjectArg, newObjectArg);
|
return this.symbolTree.appendChild(referenceObjectArg, newObjectArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================
|
||||||
|
// Functionionality that extends symbol-tree
|
||||||
|
// ===========================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a branch of the tree as JSON
|
||||||
|
* can be user
|
||||||
|
*/
|
||||||
|
toJsonWithHierachy(rootElement) {
|
||||||
|
const treeIterable = this.treeIterator(rootElement, {});
|
||||||
|
for (const treeItem of treeIterable) {
|
||||||
|
console.log(treeItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* builds a tree from a JSON with hierachy
|
||||||
|
* @param rootElement
|
||||||
|
*/
|
||||||
|
fromJsonWithHierachy(rootElement) {}
|
||||||
}
|
}
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user