2 var Mixin, PropertyAccessors, WeakMap, _ref, _ref1,
3 __hasProp = {}.hasOwnProperty,
4 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
6 Mixin = require('mixto');
8 WeakMap = (_ref = global.WeakMap) != null ? _ref : require('es6-weak-map');
10 module.exports = PropertyAccessors = (function(_super) {
11 __extends(PropertyAccessors, _super);
13 function PropertyAccessors() {
14 _ref1 = PropertyAccessors.__super__.constructor.apply(this, arguments);
18 PropertyAccessors.prototype.accessor = function(name, definition) {
19 if (typeof definition === 'function') {
24 return Object.defineProperty(this, name, definition);
27 PropertyAccessors.prototype.advisedAccessor = function(name, definition) {
28 var getAdvice, setAdvice, values;
29 if (typeof definition === 'function') {
30 getAdvice = definition;
32 getAdvice = definition.get;
33 setAdvice = definition.set;
36 return this.accessor(name, {
38 if (getAdvice != null) {
41 return values.get(this);
43 set: function(newValue) {
44 if (setAdvice != null) {
45 setAdvice.call(this, newValue, values.get(this));
47 return values.set(this, newValue);
52 PropertyAccessors.prototype.lazyAccessor = function(name, definition) {
55 return this.accessor(name, {
57 if (values.has(this)) {
58 return values.get(this);
60 values.set(this, definition.call(this));
61 return values.get(this);
64 set: function(value) {
65 return values.set(this, value);
70 return PropertyAccessors;