UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

116 lines 4.2 kB
/** * 2024-09-09: Migrated from v2/src/logic/molecules/Performance */ export function createBasePerformanceInit(editMode, monitor) { const loadPerformance = { onInit: new Date(), constructor: null, sets: {}, ops: { fetch: null, analyze: null, }, monitor: monitor, history: [], mode: editMode, }; return loadPerformance; } export function startPerformanceInit_ALVFM(editMode, monitor) { const loadPerformance = createBasePerformanceInit(editMode, monitor); return loadPerformance; } export function startPerformanceInit_SS7(classic, modern, reload, editMode, monitor) { const loadPerformance = createBasePerformanceInit(editMode, monitor); loadPerformance.spPageContextInfoClassic = classic; loadPerformance.spPageContextInfoModern = modern; loadPerformance.forceReloadScripts = reload; loadPerformance.jsEval = null; return loadPerformance; } export function startPerformOp(label, editMode, includeMsStr = false) { return startPerformOpV2({ label: label, editMode: editMode, includeMsStr: includeMsStr }); } /** * * @param label * @param editMode * @param includeMsStr - Add time MS to startStr so that it is easier to verify timing. https://github.com/mikezimm/pivottiles7/issues/192 * @returns */ export function startPerformOpV2(props) { if (!props) return null; const { includeMsStr, label, editMode, note } = props; const start = new Date(); const startStr = includeMsStr === true ? `${start.toLocaleTimeString()} ... ${start.getMilliseconds()}` : start.toLocaleTimeString(); const result = { label: label, start: start, startStr: startStr, mode: editMode ? editMode : null, details: [], //Could be used to trace individual file loads }; if (note) result.note = note; return result; } export function updatePerformanceEnd(op, updateMiliseconds, count) { return updatePerformanceEndV2({ op: op, updateMiliseconds: updateMiliseconds, count: count }); } export function updatePerformanceEndV2(props) { if (!props) return null; const { op, updateMiliseconds, count } = props; op.end = new Date(); op.endStr = op.end.toLocaleTimeString(); if (updateMiliseconds === true) op.ms = op.end.getTime() - op.start.getTime(); if (count !== null && count > 0 && op.ms) { op.c = count; op.a = Math.round((op.ms / count) * 10) / 10; } return op; } export function updatePerformOpSimple(ops, count) { if (ops.length > 0) { const last = ops.length - 1; ops[last] = updatePerformanceEnd(ops[last], true, count); } return ops; } export function startPerformOpDetail(ops, label, editMode, update = true, count = null) { if (ops) { const last = ops.length - 1; if (update === true && ops.length > 0) { ops[last] = updatePerformanceEnd(ops[last], update, count); } if (label && ops[last]) { if (typeof ops[last].details === 'object') { ops[last].details.push(startPerformOp(label, editMode, true)); // https://github.com/mikezimm/Slick-Sections/issues/69 } } else { console.log(`IPerformance ERROR: startPerformOpDetail label: ${label} ; last: ${last}`); } } return ops; } /** * * @param result * @param performanceSettings * @param fetchOp * @param key * @param resultKey */ export function unifiedPerformanceEnd(result, performanceSettings, perfOp, key, resultKey) { const resultAny = result; if (!result.unifiedPerformanceOps) result.unifiedPerformanceOps = {}; result.unifiedPerformanceOps[key] = performanceSettings ? updatePerformanceEndV2({ op: perfOp, updateMiliseconds: performanceSettings.updateMiliseconds, count: resultAny[resultKey] ? resultAny[resultKey].length : -1 }) : null; result[`${key}Op`] = result.unifiedPerformanceOps[key]; return result; } //# sourceMappingURL=functions.js.map