Skip to content

Commit

Permalink
Added functionality to find an event or meta by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
erikronstrom committed Oct 27, 2024
1 parent 8ba4bb4 commit 48613ce
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/classes/event/event-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,21 @@ export default class EventContainer extends Event {
* @return {Event?}
*/
findEvent(selector) {
if (_.isString(selector) && selector[0] === '#') {
let id = selector.substr(1);
selector = (item) => { return item.id === id; };
}
var events = this.findEvents(selector); // TODO: stop at first match instead of finding all
return events ? events[0] : null;
return events.length ? events[0] : null;
}

/**
* Find an event by ID
* @param {string} [id] - A string
* @return {Event?}
*/
findEventById(id) {
return this.findEvent((item) => { return item.id === id; });
}

/**
Expand Down Expand Up @@ -185,8 +198,21 @@ export default class EventContainer extends Event {
* @return {Event?}
*/
findMeta(selector) {
if (_.isString(selector) && selector[0] === '#') {
let id = selector.substr(1);
selector = (item) => { return item.id === id; };
}
var metas = this.findMetas(selector); // TODO: stop at first match instead of finding all
return metas ? metas[0] : null;
return metas.length ? metas[0] : null;
}

/**
* Find a meta by ID
* @param {string} [id] - A string
* @return {Event?}
*/
findMetaById(id) {
return this.findMeta((item) => { return item.id === id; });
}

/**
Expand Down

0 comments on commit 48613ce

Please sign in to comment.