Procházet zdrojové kódy

fix `clone()` to return the correct instance (#1154)

tags/3.1.0
Ulrich-Matthias Schäfer před 3 roky
rodič
revize
99e176f763
4 změnil soubory, kde provedl 11 přidání a 3 odebrání
  1. 1
    0
      CHANGELOG.md
  2. 6
    0
      spec/spec/elements/Dom.js
  3. 1
    1
      src/elements/Dom.js
  4. 3
    2
      src/utils/adopter.js

+ 1
- 0
CHANGELOG.md Zobrazit soubor

@@ -39,6 +39,7 @@ The document follows the conventions described in [“Keep a CHANGELOG”](http:
- fixed internals of ObjectBag which can hold other Morphable values now
- fixed animate transform which didnt change its origin on retarget for declaritive animations
- fixed path parsing (#1145)
- fixed `clone()` to return the correct instance (#1154)

### Added
- added second Parameter to `SVG(el, isHTML)` which allows to explicitely create elements in the HTML namespace (#1058)

+ 6
- 0
spec/spec/elements/Dom.js Zobrazit soubor

@@ -172,6 +172,12 @@ describe('Dom.js', function () {
expect(clone.get(0).id()).not.toBe(rect.id())
expect(clone.id()).not.toBe(group.id())
})

it('returns an instance of the same class the method was called on', () => {
const rect = new Dom(create('rect'))
expect(rect.constructor).toBe(Dom)
expect(rect.clone().constructor).toBe(Dom)
})
})

describe('each()', () => {

+ 1
- 1
src/elements/Dom.js Zobrazit soubor

@@ -72,7 +72,7 @@ export default class Dom extends EventTarget {
this.writeDataToDom()

// clone element and assign new id
return assignNewId(this.node.cloneNode(deep))
return new this.constructor(assignNewId(this.node.cloneNode(deep)))
}

// Iterates over all children and invokes a given block

+ 3
- 2
src/utils/adopter.js Zobrazit soubor

@@ -107,10 +107,11 @@ export function assignNewId (node) {
}

if (node.id) {
return adopt(node).id(eid(node.nodeName))
node.id = eid(node.nodeName)
return node
}

return adopt(node)
return node
}

// Method for extending objects

Načítá se…
Zrušit
Uložit