diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-01-06 15:39:22 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-01-06 15:39:22 +0100 |
commit | abf15268acafe588191fffb7ca6ddb963244bb0f (patch) | |
tree | 0f582386d09eccd550c414e62337a7f630b2ddb1 /extension/background/checkable.ts | |
parent | 2f8aa00595ab40292019ca739041296c84703899 (diff) |
Refactor wallet into logic and extension interface.
Diffstat (limited to 'extension/background/checkable.ts')
-rw-r--r-- | extension/background/checkable.ts | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/extension/background/checkable.ts b/extension/background/checkable.ts index f7e99df92..7cf50318a 100644 --- a/extension/background/checkable.ts +++ b/extension/background/checkable.ts @@ -41,6 +41,13 @@ namespace Checkable { return target; } + function checkAnyObject(target, prop): any { + if (typeof target !== "object") { + throw Error("object expected for " + prop.propertyKey); + } + return target; + } + function checkValue(target, prop): any { let type = prop.type; if (!type) { @@ -84,11 +91,7 @@ namespace Checkable { export function Value(type) { function deco(target: Object, propertyKey: string | symbol): void { - let chk = target[chkSym]; - if (!chk) { - chk = {props: []}; - target[chkSym] = chk; - } + let chk = mkChk(target); chk.props.push({ propertyKey: propertyKey, checker: checkValue, @@ -108,20 +111,26 @@ namespace Checkable { } export function Number(target: Object, propertyKey: string | symbol): void { - let chk = target[chkSym]; - if (!chk) { - chk = {props: []}; - target[chkSym] = chk; - } + let chk = mkChk(target); chk.props.push({propertyKey: propertyKey, checker: checkNumber}); } + export function AnyObject(target: Object, propertyKey: string | symbol): void { + let chk = mkChk(target); + chk.props.push({propertyKey: propertyKey, checker: checkAnyObject}); + } + export function String(target: Object, propertyKey: string | symbol): void { + let chk = mkChk(target); + chk.props.push({propertyKey: propertyKey, checker: checkString}); + } + + function mkChk(target) { let chk = target[chkSym]; if (!chk) { chk = {props: []}; target[chkSym] = chk; } - chk.props.push({propertyKey: propertyKey, checker: checkString}); + return chk; } } |