Comparing version 5.0.1 to 5.1.0
@@ -100,6 +100,25 @@ (function() { | ||
//--------------------------------------------------------------------------------------------------------- | ||
constructor() { | ||
/* thx to https://stackoverflow.com/a/40714458/7568091 */ | ||
var has_target, self; | ||
self = this; | ||
constructor(cfg) { | ||
var R, has_target; | ||
cfg = { | ||
target: this, | ||
...cfg | ||
}; | ||
//....................................................................................................... | ||
R = new Proxy(cfg.target, { | ||
//..................................................................................................... | ||
get: (target, key) => { | ||
if (key === Symbol.toStringTag) { | ||
return void 0; | ||
} | ||
if ((R = target[key]) === void 0) { | ||
throw new Error(`^guy.props.Strict_owner@1^ ${this.constructor.name} instance does not have property ${rpr(key)}`); | ||
} | ||
return R; | ||
} | ||
}); | ||
// set: ( target, key, value ) => | ||
// target[key] = value | ||
// return true | ||
//....................................................................................................... | ||
has_target = (key) => { | ||
@@ -109,7 +128,7 @@ if (key === Symbol.toStringTag) { | ||
} | ||
return self[key] !== void 0; | ||
return cfg.target[key] !== void 0; | ||
}; | ||
//....................................................................................................... | ||
if (this.has == null) { | ||
hide(this, 'has', new Proxy(has_target, { | ||
if (cfg.target.has == null) { | ||
hide(cfg.target, 'has', new Proxy(has_target, { | ||
get: (_, key) => { | ||
@@ -121,7 +140,7 @@ return has_target(key); | ||
//....................................................................................................... | ||
if (this.get == null) { | ||
hide(this, 'get', (key, fallback = misfit) => { | ||
if (cfg.target.get == null) { | ||
hide(cfg.target, 'get', (key, fallback = misfit) => { | ||
var error; | ||
try { | ||
return self[key]; | ||
return cfg.target[key]; | ||
} catch (error1) { | ||
@@ -137,15 +156,3 @@ error = error1; | ||
//....................................................................................................... | ||
return new Proxy(this, { | ||
//..................................................................................................... | ||
get: (target, key) => { | ||
var R; | ||
if (key === Symbol.toStringTag) { | ||
return void 0; | ||
} | ||
if ((R = target[key]) === void 0) { | ||
throw new Error(`^guy.props.Strict_owner@1^ ${this.constructor.name} instance does not have property ${rpr(key)}`); | ||
} | ||
return R; | ||
} | ||
}); | ||
return R; | ||
} | ||
@@ -155,8 +162,4 @@ | ||
// set: ( target, key, value ) => | ||
// target[key] = value | ||
// return true | ||
}).call(this); | ||
//# sourceMappingURL=props.js.map |
{ | ||
"name": "guy", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "npm dependencies checker", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
@@ -78,2 +78,10 @@ | ||
**Note** Most often one will want to define a class that extends `Strict_owner`, however, it is also | ||
possible to pass in an arbitrary object—including a function—as property `target` to the constructor, e.g. | ||
```coffee | ||
f = ( x ) -> x * 2 | ||
x = new GUY.props.Strict_owner { target: f, } | ||
``` | ||
### `guy.async`: Asynchronous Helpers | ||
@@ -80,0 +88,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
81064
604
304