Skip to content

Commit

Permalink
fix(core): create Ajv instance lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Poberezkin authored and Ahmad Nassri committed Mar 4, 2017
1 parent 3320cf0 commit 06cb69e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/async.js
Expand Up @@ -2,13 +2,15 @@ import * as schemas from 'har-schema'
import Ajv from 'ajv'
import HARError from './error'

// validator config
let ajv = new Ajv({
allErrors: true,
schemas: schemas
})
let ajv

export function validate (name, data = {}, next) {
// validator config
ajv = ajv || new Ajv({
allErrors: true,
schemas: schemas
})

let validate = ajv.getSchema(name + '.json')

let valid = validate(data)
Expand Down
12 changes: 7 additions & 5 deletions src/promise.js
Expand Up @@ -2,13 +2,15 @@ import * as schemas from 'har-schema'
import Ajv from 'ajv'
import HARError from './error'

// validator config
let ajv = new Ajv({
allErrors: true,
schemas: schemas
})
let ajv

export function validate (name, data = {}) {
// validator config
ajv = ajv || new Ajv({
allErrors: true,
schemas: schemas
})

let validate = ajv.getSchema(name + '.json')

return new Promise((resolve, reject) => {
Expand Down

0 comments on commit 06cb69e

Please sign in to comment.