Skip to content

Commit

Permalink
perf(functions): lazy Ajv initialization (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Sep 13, 2021
1 parent 4e8da71 commit dadf3f3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/functions/src/schema/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ function createAjvInstance(Ajv: typeof AjvCore, allErrors: boolean): AjvCore {
}

function createAjvInstances(Ajv: typeof AjvCore): { default: AjvCore; allErrors: AjvCore } {
let _default: AjvCore;
let _allErrors: AjvCore;

return {
default: createAjvInstance(Ajv, false),
allErrors: createAjvInstance(Ajv, true),
get default(): AjvCore {
_default ??= createAjvInstance(Ajv, false);
return _default;
},
get allErrors(): AjvCore {
_allErrors ??= createAjvInstance(Ajv, true);
return _allErrors;
},
};
}

Expand Down

0 comments on commit dadf3f3

Please sign in to comment.