Skip to content

Commit cd07c15

Browse files
committed
Adding getAll itemDefs
1 parent e4fe677 commit cd07c15

7 files changed

Lines changed: 58 additions & 5 deletions

File tree

docs/hds-lib.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/hds-lib.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/tests-browser.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20567,10 +20567,23 @@ class HDSModelItemsDefs {
2056720567
loadModelDataByStreamIdEventTypes(this.#model.modelData.items, this.#modelDataByStreamIdEventTypes);
2056820568
}
2056920569

20570+
/**
20571+
* get all itemDefs
20572+
* @returns {Array<HDSItemDef>}
20573+
*/
20574+
getAll () {
20575+
const res = [];
20576+
for (const key of Object.keys(this.#model.modelData.items)) {
20577+
res.push(this.forKey(key));
20578+
}
20579+
return res;
20580+
}
20581+
2057020582
/**
2057120583
* get item for a key
2057220584
* @param {string} key
2057320585
* @param {boolean} [throwErrorIfNotFound] default `true`
20586+
* @return {HDSItemDef | null}
2057420587
*/
2057520588
forKey (key, throwErrorIfNotFound = true) {
2057620589
if (this.#itemsDefs[key]) return this.#itemsDefs[key];
@@ -23959,6 +23972,16 @@ describe('[MODX] Model', () => {
2395923972
assert.deepEqual(itemDef.eventTypes, ['ratio/generic']);
2396023973
});
2396123974

23975+
it('[MODN] get All itemsDef', async () => {
23976+
const modelLoad = new HDSModel(modelURL);
23977+
await modelLoad.load();
23978+
const itemDefs = modelLoad.itemsDefs.getAll();
23979+
assert.ok(itemDefs.length > 0);
23980+
for (const itemDef of itemDefs) {
23981+
assert.ok(itemDef.key);
23982+
}
23983+
});
23984+
2396223985
// ---------- items ------------ //
2396323986
describe('[MOLX] items localization', function () {
2396423987
afterEach(() => {

docs/tests-browser.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HDSModel/HDSModel-ItemsDefs.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,23 @@ class HDSModelItemsDefs {
2727
loadModelDataByStreamIdEventTypes(this.#model.modelData.items, this.#modelDataByStreamIdEventTypes);
2828
}
2929

30+
/**
31+
* get all itemDefs
32+
* @returns {Array<HDSItemDef>}
33+
*/
34+
getAll () {
35+
const res = [];
36+
for (const key of Object.keys(this.#model.modelData.items)) {
37+
res.push(this.forKey(key));
38+
}
39+
return res;
40+
}
41+
3042
/**
3143
* get item for a key
3244
* @param {string} key
3345
* @param {boolean} [throwErrorIfNotFound] default `true`
46+
* @return {HDSItemDef | null}
3447
*/
3548
forKey (key, throwErrorIfNotFound = true) {
3649
if (this.#itemsDefs[key]) return this.#itemsDefs[key];

tests/hdsModel.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ describe('[MODX] Model', () => {
2929
assert.deepEqual(itemDef.eventTypes, ['ratio/generic']);
3030
});
3131

32+
it('[MODN] get All itemsDef', async () => {
33+
const modelLoad = new HDSModel(modelURL);
34+
await modelLoad.load();
35+
const itemDefs = modelLoad.itemsDefs.getAll();
36+
assert.ok(itemDefs.length > 0);
37+
for (const itemDef of itemDefs) {
38+
assert.ok(itemDef.key);
39+
}
40+
});
41+
3242
// ---------- items ------------ //
3343
describe('[MOLX] items localization', function () {
3444
afterEach(() => {

types/HDSModel/HDSModel-ItemsDefs.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@ export = HDSModelItemsDefs;
77
*/
88
declare class HDSModelItemsDefs {
99
constructor(model: HDSModel);
10+
/**
11+
* get all itemDefs
12+
* @returns {Array<HDSItemDef>}
13+
*/
14+
getAll(): HDSItemDef[];
15+
1016
/**
1117
* get item for a key
1218
* @param {string} key
1319
* @param {boolean} [throwErrorIfNotFound] default `true`
1420
*/
15-
forKey(key: string, throwErrorIfNotFound?: boolean): HDSItemDef;
21+
forKey(key: string, throwErrorIfNotFound?: boolean): HDSItemDef | null;
22+
1623
/**
1724
* get a definition for an event
1825
* @param {Event} event
1926
* @param {boolean} [throwErrorIfNotFound] default `true`
2027
*/
21-
forEvent(event: pryv.Event, throwErrorIfNotFound?: boolean): HDSItemDef;
28+
forEvent(event: pryv.Event, throwErrorIfNotFound?: boolean): HDSItemDef | null;
2229
#private;
2330
}

0 commit comments

Comments
 (0)