factory-girl
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -1023,3 +1023,3 @@ import _slicedToArray from 'babel-runtime/helpers/slicedToArray'; | ||
value: function cleanUp() { | ||
var promises = []; | ||
var createdArray = []; | ||
var _iteratorNormalCompletion2 = true; | ||
@@ -1031,8 +1031,5 @@ var _didIteratorError2 = false; | ||
for (var _iterator2 = _getIterator(this.created), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _step2$value = _slicedToArray(_step2.value, 2); | ||
var c = _step2.value; | ||
var adapter = _step2$value[0]; | ||
var model = _step2$value[1]; | ||
promises.push(adapter.destroy(model, model.constructor)); | ||
createdArray.push(c); | ||
} | ||
@@ -1054,5 +1051,14 @@ } catch (err) { | ||
var promise = createdArray.reduce(function (prev, _ref6) { | ||
var _ref7 = _slicedToArray(_ref6, 2); | ||
var adapter = _ref7[0]; | ||
var model = _ref7[1]; | ||
return prev.then(function () { | ||
return adapter.destroy(model, model.constructor); | ||
}); | ||
}, _Promise.resolve()); | ||
this.created.clear(); | ||
this.resetSeq(); | ||
return _Promise.all(promises); | ||
return promise; | ||
} | ||
@@ -1059,0 +1065,0 @@ }, { |
20
index.js
@@ -1029,3 +1029,3 @@ 'use strict'; | ||
value: function cleanUp() { | ||
var promises = []; | ||
var createdArray = []; | ||
var _iteratorNormalCompletion2 = true; | ||
@@ -1037,8 +1037,5 @@ var _didIteratorError2 = false; | ||
for (var _iterator2 = _getIterator(this.created), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _step2$value = _slicedToArray(_step2.value, 2); | ||
var c = _step2.value; | ||
var adapter = _step2$value[0]; | ||
var model = _step2$value[1]; | ||
promises.push(adapter.destroy(model, model.constructor)); | ||
createdArray.push(c); | ||
} | ||
@@ -1060,5 +1057,14 @@ } catch (err) { | ||
var promise = createdArray.reduce(function (prev, _ref6) { | ||
var _ref7 = _slicedToArray(_ref6, 2); | ||
var adapter = _ref7[0]; | ||
var model = _ref7[1]; | ||
return prev.then(function () { | ||
return adapter.destroy(model, model.constructor); | ||
}); | ||
}, _Promise.resolve()); | ||
this.created.clear(); | ||
this.resetSeq(); | ||
return _Promise.all(promises); | ||
return promise; | ||
} | ||
@@ -1065,0 +1071,0 @@ }, { |
@@ -1029,3 +1029,3 @@ (function (global, factory) { | ||
value: function cleanUp() { | ||
var promises = []; | ||
var createdArray = []; | ||
var _iteratorNormalCompletion2 = true; | ||
@@ -1037,8 +1037,5 @@ var _didIteratorError2 = false; | ||
for (var _iterator2 = _getIterator(this.created), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _step2$value = _slicedToArray(_step2.value, 2); | ||
var c = _step2.value; | ||
var adapter = _step2$value[0]; | ||
var model = _step2$value[1]; | ||
promises.push(adapter.destroy(model, model.constructor)); | ||
createdArray.push(c); | ||
} | ||
@@ -1060,5 +1057,14 @@ } catch (err) { | ||
var promise = createdArray.reduce(function (prev, _ref6) { | ||
var _ref7 = _slicedToArray(_ref6, 2); | ||
var adapter = _ref7[0]; | ||
var model = _ref7[1]; | ||
return prev.then(function () { | ||
return adapter.destroy(model, model.constructor); | ||
}); | ||
}, _Promise.resolve()); | ||
this.created.clear(); | ||
this.resetSeq(); | ||
return _Promise.all(promises); | ||
return promise; | ||
} | ||
@@ -1065,0 +1071,0 @@ }, { |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"keywords": [ | ||
@@ -12,0 +12,0 @@ "factory", |
@@ -115,3 +115,3 @@ # factory-girl | ||
Provides a function that is called after the model is built. | ||
The function should return the instance or throw an error. For asynchronous functions, it should return a promise that either resolves with the instance or rejects with the error. | ||
The function should return the instance or a Promise for the instance. | ||
@@ -240,2 +240,21 @@ #### `afterCreate: function(model, attrs, buildOptions)` | ||
### ObjectAdapter | ||
`ObjectAdapter` is a simple adapter that uses `const model = new MyModel()`, | ||
`model.save()` and `model.destroy()`. | ||
```js | ||
factory.setAdapter(new factory.ObjectAdapter()); | ||
class MyModel { | ||
save() { | ||
// save the model | ||
}, | ||
destroy() { | ||
// destroy the model | ||
} | ||
} | ||
} | ||
factory.define('model', MyModel); | ||
``` | ||
## Creating new Factories | ||
@@ -242,0 +261,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
703678
14288
288