From 54a73ca91e192111cf2988e1a915e09d46569207 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Wed, 18 Oct 2017 09:11:15 +0200 Subject: [PATCH] Fix issue regarding resetting of the predicate chain --- source/ow.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/source/ow.ts b/source/ow.ts index e50827d..ae44740 100644 --- a/source/ow.ts +++ b/source/ow.ts @@ -10,16 +10,19 @@ export interface Ow { string: StringPredicate; } -export const ow: Ow = Object.assign( - (value: any, predicate: Predicate) => { - for (const { validator, message } of predicate[validatorSymbol]) { - if (!validator(value)) { - // TODO: Modify the stack output to show the original `ow()` call instead of this `throw` statement - throw new ArgumentError(message(value), ow); - } +const main = (value: any, predicate: Predicate) => { + for (const { validator, message } of predicate[validatorSymbol]) { + if (!validator(value)) { + // TODO: Modify the stack output to show the original `ow()` call instead of this `throw` statement + throw new ArgumentError(message(value), main); } - }, - { - string: new StringPredicate() } -); +}; + +Object.defineProperties(main, { + string: { + get: () => new StringPredicate() + } +}); + +export const ow = main as Ow;