You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
545 B

4 years ago
  1. 'use strict';
  2. module.exports = function replace(items) {
  3. if (!items) {
  4. return this;
  5. }
  6. if (Array.isArray(items)) {
  7. var _replaced = this.items.map(function (value, index) {
  8. return items[index] || value;
  9. });
  10. return new this.constructor(_replaced);
  11. }
  12. if (items.constructor.name === 'Collection') {
  13. var _replaced2 = Object.assign({}, this.items, items.all());
  14. return new this.constructor(_replaced2);
  15. }
  16. var replaced = Object.assign({}, this.items, items);
  17. return new this.constructor(replaced);
  18. };