Comparing version 2.0.0 to 2.0.2
@@ -10,3 +10,3 @@ 'use strict'; | ||
var _desc, _value, _class; | ||
var _desc, _value, _class, _descriptor, _descriptor2; | ||
@@ -21,2 +21,10 @@ var _mobx = require('mobx'); | ||
var _ErrorObject = require('./ErrorObject'); | ||
var _ErrorObject2 = _interopRequireDefault(_ErrorObject); | ||
var _Request = require('./Request'); | ||
var _Request2 = _interopRequireDefault(_Request); | ||
var _apiClient = require('./apiClient'); | ||
@@ -30,2 +38,12 @@ | ||
function _initDefineProp(target, property, descriptor, context) { | ||
if (!descriptor) return; | ||
Object.defineProperty(target, property, { | ||
enumerable: descriptor.enumerable, | ||
configurable: descriptor.configurable, | ||
writable: descriptor.writable, | ||
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 | ||
}); | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -62,2 +80,6 @@ | ||
function _initializerWarningHelper(descriptor, context) { | ||
throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); | ||
} | ||
var Collection = (_class = function () { | ||
@@ -69,4 +91,6 @@ function Collection() { | ||
this.request = _mobx.observable.shallowObject(null); | ||
this.error = _mobx.observable.shallowObject(null); | ||
_initDefineProp(this, 'request', _descriptor, this); | ||
_initDefineProp(this, 'error', _descriptor2, this); | ||
this.models = _mobx.observable.shallowArray([]); | ||
@@ -101,2 +125,13 @@ | ||
/** | ||
* Returns a JSON representation | ||
* of the collection | ||
*/ | ||
}, { | ||
key: 'toJS', | ||
value: function toJS() { | ||
return (0, _mobx.toJS)(this.models); | ||
} | ||
/** | ||
* Questions whether the request exists | ||
@@ -313,14 +348,6 @@ * and matches a certain label | ||
model = attributesOrModel instanceof _Model2.default ? attributesOrModel : (0, _lodash.last)(this.add([attributesOrModel])); | ||
model.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
model.request = new _Request2.default(label, abort, 0); | ||
} | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
@@ -345,3 +372,3 @@ data = void 0; | ||
} | ||
_this4.error = { label: label, body: _context.t0 }; | ||
_this4.error = new _ErrorObject2.default(label, _context.t0); | ||
_this4.request = null; | ||
@@ -407,7 +434,3 @@ }); | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
@@ -429,3 +452,3 @@ data = void 0; | ||
(0, _mobx.runInAction)('fetch-error', function () { | ||
_this5.error = { label: label, body: _context2.t0 }; | ||
_this5.error = new _ErrorObject2.default(label, _context2.t0); | ||
_this5.request = null; | ||
@@ -483,7 +506,3 @@ }); | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
@@ -506,3 +525,3 @@ response = void 0; | ||
_this6.request = null; | ||
_this6.error = { label: label, body: _context3.t0 }; | ||
_this6.error = new _ErrorObject2.default(label, _context3.t0); | ||
}); | ||
@@ -535,3 +554,13 @@ | ||
return Collection; | ||
}(), (_applyDecoratedDescriptor(_class.prototype, 'add', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'remove', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'remove'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'set', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'set'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'create', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'create'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fetch', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'fetch'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'rpc', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'rpc'), _class.prototype)), _class); | ||
}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'request', [_mobx.observable], { | ||
enumerable: true, | ||
initializer: function initializer() { | ||
return null; | ||
} | ||
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'error', [_mobx.observable], { | ||
enumerable: true, | ||
initializer: function initializer() { | ||
return null; | ||
} | ||
}), _applyDecoratedDescriptor(_class.prototype, 'add', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'add'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'remove', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'remove'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'set', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'set'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'create', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'create'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fetch', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'fetch'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'rpc', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'rpc'), _class.prototype)), _class); | ||
exports.default = Collection; |
101
lib/Model.js
@@ -10,3 +10,3 @@ 'use strict'; | ||
var _desc, _value, _class; | ||
var _desc, _value, _class, _descriptor, _descriptor2; | ||
@@ -25,2 +25,10 @@ var _mobx = require('mobx'); | ||
var _Request = require('./Request'); | ||
var _Request2 = _interopRequireDefault(_Request); | ||
var _ErrorObject = require('./ErrorObject'); | ||
var _ErrorObject2 = _interopRequireDefault(_ErrorObject); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -30,2 +38,12 @@ | ||
function _initDefineProp(target, property, descriptor, context) { | ||
if (!descriptor) return; | ||
Object.defineProperty(target, property, { | ||
enumerable: descriptor.enumerable, | ||
configurable: descriptor.configurable, | ||
writable: descriptor.writable, | ||
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 | ||
}); | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -62,2 +80,6 @@ | ||
function _initializerWarningHelper(descriptor, context) { | ||
throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.'); | ||
} | ||
var Model = (_class = function () { | ||
@@ -69,4 +91,6 @@ function Model() { | ||
this.request = _mobx.observable.shallowObject(null); | ||
this.error = _mobx.observable.shallowObject(null); | ||
_initDefineProp(this, 'request', _descriptor, this); | ||
_initDefineProp(this, 'error', _descriptor2, this); | ||
this.optimisticId = (0, _lodash.uniqueId)('i_'); | ||
@@ -79,6 +103,4 @@ this.collection = null; | ||
/** | ||
* Return the base url used in | ||
* the `url` method | ||
* | ||
* @abstract | ||
* Returns a JSON representation | ||
* of the model | ||
*/ | ||
@@ -88,2 +110,15 @@ | ||
_createClass(Model, [{ | ||
key: 'toJS', | ||
value: function toJS() { | ||
return (0, _mobx.toJS)(this.attributes); | ||
} | ||
/** | ||
* Return the base url used in | ||
* the `url` method | ||
* | ||
* @abstract | ||
*/ | ||
}, { | ||
key: 'urlRoot', | ||
@@ -194,7 +229,3 @@ value: function urlRoot() { | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
@@ -216,3 +247,3 @@ data = void 0; | ||
(0, _mobx.runInAction)('fetch-error', function () { | ||
_this.error = { label: label, body: _context.t0 }; | ||
_this.error = new _ErrorObject2.default(label, _context.t0); | ||
_this.request = null; | ||
@@ -313,7 +344,3 @@ }); | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
@@ -337,3 +364,3 @@ response = void 0; | ||
_this2.set(originalAttributes); | ||
_this2.error = { label: label, body: _context2.t0 }; | ||
_this2.error = new _ErrorObject2.default(label, _context2.t0); | ||
}); | ||
@@ -398,7 +425,3 @@ | ||
if (optimistic) { | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
} | ||
@@ -421,3 +444,3 @@ | ||
(0, _mobx.runInAction)('create-error', function () { | ||
_this3.error = { label: label, body: _context3.t0 }; | ||
_this3.error = new _ErrorObject2.default(label, _context3.t0); | ||
_this3.request = null; | ||
@@ -491,7 +514,3 @@ }); | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
@@ -514,3 +533,3 @@ _context4.prev = 7; | ||
} | ||
_this4.error = { label: label, body: _context4.t0 }; | ||
_this4.error = new _ErrorObject2.default(label, _context4.t0); | ||
_this4.request = null; | ||
@@ -570,7 +589,3 @@ }); | ||
this.request = { | ||
label: label, | ||
abort: abort, | ||
progress: 0 | ||
}; | ||
this.request = new _Request2.default(label, abort, 0); | ||
@@ -593,3 +608,3 @@ response = void 0; | ||
_this5.request = null; | ||
_this5.error = { label: label, body: _context5.t0 }; | ||
_this5.error = new _ErrorObject2.default(label, _context5.t0); | ||
}); | ||
@@ -638,3 +653,13 @@ | ||
return Model; | ||
}(), (_applyDecoratedDescriptor(_class.prototype, 'isNew', [_mobx.computed], Object.getOwnPropertyDescriptor(_class.prototype, 'isNew'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'set', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'set'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fetch', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'fetch'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'save', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'destroy', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'destroy'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'rpc', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'rpc'), _class.prototype)), _class); | ||
}(), (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'request', [_mobx.observable], { | ||
enumerable: true, | ||
initializer: function initializer() { | ||
return null; | ||
} | ||
}), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, 'error', [_mobx.observable], { | ||
enumerable: true, | ||
initializer: function initializer() { | ||
return null; | ||
} | ||
}), _applyDecoratedDescriptor(_class.prototype, 'isNew', [_mobx.computed], Object.getOwnPropertyDescriptor(_class.prototype, 'isNew'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'set', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'set'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fetch', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'fetch'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'save', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'destroy', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'destroy'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'rpc', [_mobx.action], Object.getOwnPropertyDescriptor(_class.prototype, 'rpc'), _class.prototype)), _class); | ||
exports.default = Model; |
{ | ||
"name": "mobx-rest", | ||
"version": "2.0.0", | ||
"version": "2.0.2", | ||
"description": "REST conventions for mobx.", | ||
@@ -5,0 +5,0 @@ "repository": { |
67729
18
1678