UNPKG

superfly-timeline

Version:

Resolver for defining objects with temporal boolean logic relationships on a timeline

34 lines 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortEvents = void 0; function sortEvents(events, additionalSortFcnBefore) { return events.sort((a, b) => { if (a.time > b.time) return 1; if (a.time < b.time) return -1; const result = additionalSortFcnBefore ? additionalSortFcnBefore(a, b) : 0; if (result !== 0) return result; const aId = a.data && (a.data.id || a.data.instance?.id); const bId = b.data && (b.data.id || b.data.instance?.id); if (aId && bId && aId === bId) { // If the events refer to the same instance id, let the start event be first, // to handle zero-length instances. if (a.value && !b.value) return -1; if (!a.value && b.value) return 1; } else { // ends events first: if (a.value && !b.value) return 1; if (!a.value && b.value) return -1; } return 0; }); } exports.sortEvents = sortEvents; //# sourceMappingURL=event.js.map