Comparing version 0.0.12 to 0.0.13
@@ -253,14 +253,18 @@ 'use strict'; | ||
return promise.then(function (data) { | ||
if (model) { | ||
model.set(data); | ||
model.request = null; | ||
} else { | ||
_this4.add([data]); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
promise.then(function (data) { | ||
if (model) { | ||
model.set(data); | ||
model.request = null; | ||
} else { | ||
_this4.add([data]); | ||
} | ||
return data; | ||
}).catch(function (body) { | ||
if (model) _this4.remove([model.id]); | ||
_this4.error = { label: label, body: body }; | ||
resolve(data); | ||
}).catch(function (body) { | ||
if (model) _this4.remove([model.id]); | ||
_this4.error = { label: label, body: body }; | ||
reject(body); | ||
}); | ||
}); | ||
@@ -294,10 +298,14 @@ } | ||
return promise.then(function (data) { | ||
_this5.request = null; | ||
_this5.set(data, options); | ||
return new Promise(function (resolve, reject) { | ||
promise.then(function (data) { | ||
_this5.request = null; | ||
_this5.set(data, options); | ||
return data; | ||
}).catch(function (body) { | ||
_this5.request = null; | ||
_this5.error = { label: label, body: body }; | ||
resolve(data); | ||
}).catch(function (body) { | ||
_this5.request = null; | ||
_this5.error = { label: label, body: body }; | ||
reject(body); | ||
}); | ||
}); | ||
@@ -304,0 +312,0 @@ } |
@@ -133,11 +133,15 @@ 'use strict'; | ||
return promise.then(function (data) { | ||
_this.request = null; | ||
_this.set(data); | ||
return new Promise(function (resolve, reject) { | ||
promise.then(function (data) { | ||
_this.request = null; | ||
_this.set(data); | ||
return data; | ||
}).catch(function (body) { | ||
_this.request = null; | ||
_this.attributes = (0, _mobx.asMap)(originalAttributes); | ||
_this.error = { label: label, body: body }; | ||
resolve(data); | ||
}).catch(function (body) { | ||
_this.request = null; | ||
_this.attributes = (0, _mobx.asMap)(originalAttributes); | ||
_this.error = { label: label, body: body }; | ||
reject(body); | ||
}); | ||
}); | ||
@@ -172,9 +176,15 @@ } | ||
return promise.then(function () { | ||
if (!optimistic) _this2.collection.remove([_this2.id]); | ||
_this2.request = null; | ||
}).catch(function (body) { | ||
if (optimistic) _this2.collection.add([_this2.attributes.toJS()]); | ||
_this2.error = { label: label, body: body }; | ||
_this2.request = null; | ||
return new Promise(function (resolve, reject) { | ||
return promise.then(function () { | ||
if (!optimistic) _this2.collection.remove([_this2.id]); | ||
_this2.request = null; | ||
resolve(); | ||
}).catch(function (body) { | ||
if (optimistic) _this2.collection.add([_this2.attributes.toJS()]); | ||
_this2.error = { label: label, body: body }; | ||
_this2.request = null; | ||
reject(body); | ||
}); | ||
}); | ||
@@ -181,0 +191,0 @@ } |
{ | ||
"name": "mobx-rest", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "REST conventions for mobx.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -77,3 +77,3 @@ /*global describe, it, context, beforeEach*/ | ||
it('sets the error', () => { | ||
return collection.create(newItem).then(() => { | ||
return collection.create(newItem).catch(() => { | ||
assert.equal(collection.error.label, 'creating') | ||
@@ -85,3 +85,3 @@ assert.equal(collection.error.body, error) | ||
it('removes the model', () => { | ||
return collection.create(newItem).then(() => { | ||
return collection.create(newItem).catch(() => { | ||
assert.equal(collection.models.length, 1) | ||
@@ -118,3 +118,3 @@ }) | ||
it('sets the error', () => { | ||
return collection.create(newItem, {optimistic: false}).then(() => { | ||
return collection.create(newItem, {optimistic: false}).catch(() => { | ||
assert.equal(collection.error.label, 'creating') | ||
@@ -132,3 +132,3 @@ assert.equal(collection.error.body, error) | ||
it('adds data from the server', () => { | ||
return collection.create(newItem, {optimistic: false}).then(() => { | ||
return collection.create(newItem, {optimistic: false}).catch(() => { | ||
assert.equal(collection.models.length, 2) | ||
@@ -152,3 +152,3 @@ assert.equal(collection.at(1).get('name'), 'dylan') | ||
it('sets the error', () => { | ||
return collection.fetch().then(() => { | ||
return collection.fetch().catch(() => { | ||
assert.equal(collection.error.label, 'fetching') | ||
@@ -155,0 +155,0 @@ assert.equal(collection.error.body, error) |
@@ -85,3 +85,3 @@ /*global describe, it, context, beforeEach*/ | ||
it('sets the error', () => { | ||
return model.save({name}).then(() => { | ||
return model.save({name}).catch(() => { | ||
assert.equal(model.error.label, 'updating') | ||
@@ -93,3 +93,3 @@ assert.equal(model.error.body, error) | ||
it('rolls back the changes', () => { | ||
return model.save({name}).then(() => { | ||
return model.save({name}).catch(() => { | ||
assert.equal(model.get('name'), item.name) | ||
@@ -102,3 +102,3 @@ assert.equal(model.get('album'), item.album) | ||
it('nullifies the request', () => { | ||
return model.save({name}).then(() => { | ||
return model.save({name}).catch(() => { | ||
assert.equal(model.request, null) | ||
@@ -133,3 +133,3 @@ }) | ||
it('sets the error', () => { | ||
return model.save({name}, {optimistic: false}).then(() => { | ||
return model.save({name}, {optimistic: false}).catch(() => { | ||
assert.equal(model.error.label, 'updating') | ||
@@ -141,3 +141,3 @@ assert.equal(model.error.body, error) | ||
it('nullifies the request', () => { | ||
return model.save({name}).then(() => { | ||
return model.save({name}).catch(() => { | ||
assert.equal(model.request, null) | ||
@@ -189,3 +189,3 @@ }) | ||
it('sets the error', () => { | ||
return model.destroy().then(() => { | ||
return model.destroy().catch(() => { | ||
assert.equal(model.error.label, 'destroying') | ||
@@ -197,3 +197,3 @@ assert.equal(model.error.body, error) | ||
it('rolls back the changes', () => { | ||
return model.destroy().then(() => { | ||
return model.destroy().catch(() => { | ||
assert.equal(collection.models.length, 1) | ||
@@ -205,3 +205,3 @@ assert.equal(collection.at(0).get('name'), item.name) | ||
it('nullifies the request', () => { | ||
return model.destroy().then(() => { | ||
return model.destroy().catch(() => { | ||
assert.equal(model.request, null) | ||
@@ -228,3 +228,3 @@ }) | ||
it('sets the error', () => { | ||
return model.destroy({optimistic: false}).then(() => { | ||
return model.destroy({optimistic: false}).catch(() => { | ||
assert.equal(model.error.label, 'destroying') | ||
@@ -236,3 +236,3 @@ assert.equal(model.error.body, error) | ||
it('rolls back the changes', () => { | ||
return model.destroy({optimistic: false}).then(() => { | ||
return model.destroy({optimistic: false}).catch(() => { | ||
assert.equal(collection.models.length, 1) | ||
@@ -243,3 +243,3 @@ }) | ||
it('nullifies the request', () => { | ||
return model.destroy({optimistic: false}).then(() => { | ||
return model.destroy({optimistic: false}).catch(() => { | ||
assert.equal(model.request, null) | ||
@@ -246,0 +246,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39028
897