Skip to content

Commit 2690eaa

Browse files
committed
Bugfix node 5.x
1 parent a9ad4d5 commit 2690eaa

File tree

5 files changed

+17
-61
lines changed

5 files changed

+17
-61
lines changed

.babelrc

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"presets": [
33
"es2015"
4-
],
5-
"plugins": [
6-
[ "transform-builtin-extend", { "globals": [ "Error" ] } ]
74
]
85
}

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- "6"
34
- "5"
45
services:
56
- mongodb

lib/index.js

+10-50
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports.default = function (schema, opts) {
3232

3333
// roll the document back to the state of a given patch id
3434
schema.methods.rollback = function (patchId, data) {
35-
var _this2 = this;
35+
var _this = this;
3636

3737
return this.patches.find({ ref: this.id }).sort({ date: 1 }).exec().then(function (patches) {
3838
return new _bluebird2.default(function (resolve, reject) {
@@ -59,7 +59,7 @@ exports.default = function (schema, opts) {
5959
});
6060

6161
// save new state and resolve with the resulting document
62-
_this2.set((0, _lodash.merge)(data, state)).save().then(resolve).catch(reject);
62+
_this.set((0, _lodash.merge)(data, state)).save().then(resolve).catch(reject);
6363
});
6464
});
6565
};
@@ -101,7 +101,7 @@ exports.default = function (schema, opts) {
101101
// document has changed), a new patch document reflecting the changes is
102102
// added to the associated patch collection
103103
schema.pre('save', function (next) {
104-
var _this3 = this;
104+
var _this2 = this;
105105

106106
var ref = this._id;
107107

@@ -115,7 +115,7 @@ exports.default = function (schema, opts) {
115115
// assemble patch data
116116
var data = { ops: ops, ref: ref };
117117
(0, _lodash.each)(options.includes, function (type, name) {
118-
data[name] = _this3[type.from || name];
118+
data[name] = _this2[type.from || name];
119119
});
120120

121121
this.patches.create(data).then(next).catch(next);
@@ -142,53 +142,13 @@ var _lodash = require('lodash');
142142

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

145-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
146-
147-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
148-
149-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
150-
151-
function _extendableBuiltin(cls) {
152-
function ExtendableBuiltin() {
153-
var instance = Reflect.construct(cls, Array.from(arguments));
154-
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
155-
return instance;
156-
}
157-
158-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
159-
constructor: {
160-
value: cls,
161-
enumerable: false,
162-
writable: true,
163-
configurable: true
164-
}
165-
});
166-
167-
if (Object.setPrototypeOf) {
168-
Object.setPrototypeOf(ExtendableBuiltin, cls);
169-
} else {
170-
ExtendableBuiltin.__proto__ = cls;
171-
}
172-
173-
return ExtendableBuiltin;
174-
}
175-
176-
var RollbackError = exports.RollbackError = function (_extendableBuiltin2) {
177-
_inherits(RollbackError, _extendableBuiltin2);
178-
179-
function RollbackError(message) {
180-
_classCallCheck(this, RollbackError);
181-
182-
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RollbackError).call(this));
183-
184-
Error.captureStackTrace(_this, _this.constructor);
185-
_this.name = _this.constructor.name;
186-
_this.message = message;
187-
return _this;
188-
}
145+
var RollbackError = exports.RollbackError = function RollbackError(message, extra) {
146+
Error.captureStackTrace(this, this.constructor);
147+
this.name = 'RollbackError';
148+
this.message = message;
149+
};
189150

190-
return RollbackError;
191-
}(_extendableBuiltin(Error));
151+
require('util').inherits(RollbackError, Error);
192152

193153
var createPatchModel = function createPatchModel(options) {
194154
var def = {

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"devDependencies": {
1515
"babel-cli": "^6.7.7",
1616
"babel-preset-es2015": "^6.6.0",
17-
"babel-plugin-transform-builtin-extend": "^1.1.0",
1817
"bluebird": "^3.3.5",
1918
"coveralls": "^2.11.9",
2019
"eslint": "^2.9.0",

src/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import jsonpatch from 'fast-json-patch'
55
import { decamelize, pascalize } from 'humps'
66
import { dropRightWhile, each, map, merge, omit } from 'lodash'
77

8-
export class RollbackError extends Error {
9-
constructor (message) {
10-
super()
11-
Error.captureStackTrace(this, this.constructor)
12-
this.name = this.constructor.name
13-
this.message = message
14-
}
8+
export const RollbackError = function (message, extra) {
9+
Error.captureStackTrace(this, this.constructor)
10+
this.name = 'RollbackError'
11+
this.message = message
1512
}
1613

14+
require('util').inherits(RollbackError, Error)
15+
1716
const createPatchModel = (options) => {
1817
const def = {
1918
date: { type: Date, required: true, default: Date.now },

0 commit comments

Comments
 (0)