Skip to content

Commit 5ac4a55

Browse files
committed
Using attributeChangedCallback makes this a bit easier
1 parent 041be27 commit 5ac4a55

File tree

2 files changed

+14
-42
lines changed

2 files changed

+14
-42
lines changed

dist/x-gif.raw.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,22 +2046,6 @@ var Strategies = $traceurRuntime.assertObject(require('./strategies.js')).defaul
20462046
this.playback.start();
20472047
}
20482048
};
2049-
var observer = new MutationObserver((function(mutations) {
2050-
mutations.forEach((function(mutation) {
2051-
if (mutation.attributeName == "src")
2052-
$__0.srcChanged(mutation.target.getAttribute(mutation.attributeName));
2053-
if (mutation.attributeName == "speed")
2054-
$__0.speedChanged(mutation.target.getAttribute(mutation.attributeName));
2055-
if (mutation.attributeName == "stopped")
2056-
$__0.stoppedChanged(mutation.target.getAttribute(mutation.attributeName));
2057-
}));
2058-
}));
2059-
observer.observe(context, {
2060-
attributes: true,
2061-
attributeOldValue: true,
2062-
childList: false,
2063-
characterData: false
2064-
});
20652049
context.togglePingPong = (function() {
20662050
if (context.hasAttribute('ping-pong')) {
20672051
context.removeAttribute('ping-pong');
@@ -2084,8 +2068,13 @@ var Strategies = $traceurRuntime.assertObject(require('./strategies.js')).defaul
20842068
XGif.createdCallback = function() {
20852069
this.controller = new XGifController(this);
20862070
};
2087-
XGif.attributeChangedCallback = function() {
2088-
console.log(arguments);
2071+
XGif.attributeChangedCallback = function(attribute, oldVal, newVal) {
2072+
if (attribute == "src")
2073+
this.controller.srcChanged(newVal);
2074+
if (attribute == "speed")
2075+
this.controller.speedChanged(newVal);
2076+
if (attribute == "stopped")
2077+
this.controller.stoppedChanged(newVal);
20892078
};
20902079
document.registerElement('x-gif', {prototype: XGif});
20912080
})(document, (document._currentScript || document.currentScript).ownerDocument);

src/x-gif.raw.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import Playback from './playback.js';
44
import Strategies from './strategies.js';
55

6-
(function(document, owner){
6+
(function (document, owner) {
77

8-
var XGifController = function(context){
8+
var XGifController = function (context) {
99
// save the context to the custom element
1010
this.context = context;
1111

@@ -57,25 +57,6 @@ import Strategies from './strategies.js';
5757
}
5858
}
5959

60-
var observer = new MutationObserver(mutations => {
61-
mutations.forEach(mutation => {
62-
// console.log({
63-
// mutation: mutation,
64-
// el: mutation.target,
65-
// old: mutation.oldValue,
66-
// new: mutation.target.getAttribute(mutation.attributeName)
67-
// })
68-
if (mutation.attributeName == "src") this.srcChanged(mutation.target.getAttribute(mutation.attributeName))
69-
if (mutation.attributeName == "speed") this.speedChanged(mutation.target.getAttribute(mutation.attributeName))
70-
if (mutation.attributeName == "stopped") this.stoppedChanged(mutation.target.getAttribute(mutation.attributeName))
71-
})
72-
})
73-
observer.observe(context, {
74-
attributes: true,
75-
attributeOldValue: true,
76-
childList: false,
77-
characterData: false
78-
});
7960
// src speed bpm hard-bpm exploded n-times ping-pong sync fill stopped
8061

8162
context.togglePingPong = () => {
@@ -98,11 +79,13 @@ import Strategies from './strategies.js';
9879

9980
// Register the element in the document
10081
var XGif = Object.create(HTMLElement.prototype);
101-
XGif.createdCallback = function(){
82+
XGif.createdCallback = function () {
10283
this.controller = new XGifController(this);
10384
};
104-
XGif.attributeChangedCallback = function () {
105-
console.log(arguments)
85+
XGif.attributeChangedCallback = function (attribute, oldVal, newVal) {
86+
if (attribute == "src") this.controller.srcChanged(newVal)
87+
if (attribute == "speed") this.controller.speedChanged(newVal)
88+
if (attribute == "stopped") this.controller.stoppedChanged(newVal)
10689
}
10790

10891
// Register our todo-item tag with the document

0 commit comments

Comments
 (0)