Skip to content
This repository has been archived by the owner on Feb 21, 2018. It is now read-only.

Commit

Permalink
version
Browse files Browse the repository at this point in the history
  • Loading branch information
giogonzo committed Jun 2, 2015
1 parent 2de5996 commit 9e7548b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
33 changes: 33 additions & 0 deletions lib/decorators/autobound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

exports.__esModule = true;
exports['default'] = autobound;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _tcomb = require('tcomb');

var _tcomb2 = _interopRequireDefault(_tcomb);

function autobound(target, key, descriptor) {
var value = descriptor.value;

if (process.env.NODE_ENV !== 'production') {
_tcomb2['default'].assert(_tcomb2['default'].Func.is(value), '@autobound decorator can only be applied to methods');
}

return {
configurable: true,
get: function get() {
var boundValue = value.bind(this);
Object.defineProperty(this, key, {
value: boundValue,
configurable: true,
writable: true
});
return boundValue;
}
};
}

module.exports = exports['default'];
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ var _decoratorsSkinnable = require('./decorators/skinnable');

var _decoratorsSkinnable2 = _interopRequireDefault(_decoratorsSkinnable);

exports.skinnable = _decoratorsSkinnable2['default'];
exports.skinnable = _decoratorsSkinnable2['default'];

var _decoratorsAutobound = require('./decorators/autobound');

var _decoratorsAutobound2 = _interopRequireDefault(_decoratorsAutobound);

exports.autobound = _decoratorsAutobound2['default'];

0 comments on commit 9e7548b

Please sign in to comment.