aboutsummaryrefslogtreecommitdiff
path: root/extension/background/checkable.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-01-06 15:39:22 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-01-06 15:39:22 +0100
commitabf15268acafe588191fffb7ca6ddb963244bb0f (patch)
tree0f582386d09eccd550c414e62337a7f630b2ddb1 /extension/background/checkable.ts
parent2f8aa00595ab40292019ca739041296c84703899 (diff)
Refactor wallet into logic and extension interface.
Diffstat (limited to 'extension/background/checkable.ts')
-rw-r--r--extension/background/checkable.ts31
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;
}
}