BlueGit

timfa frameworkv3

Fix medium lifecycle, input, and particle edge cases.

Harden destroy/removal, Signal index-0 handling, transform size, and particle updates so scene teardown and gameplay utilities behave reliably.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-08-10 · 3 months ago

Hash
36c138d370408d9cd20bac5eb34852ae88d0efbc
Parent
ac705e00
9 files changed +124 −60
framework/engine/game.js +10 −11
@@ -129,11 +129,10 @@ class Game
129 129
130 130 removeScene (scene)
131 131 {
132 const index = this.activeScenes.indexOf(scene);
133 if (index >= 0 && !scene.destroyed)
132 if (this.activeScenes.indexOf(scene) >= 0)
134 133 {
135 if (!this.pendingRemoval.contains(index))
136 { this.pendingRemoval.push(index); }
134 if (!this.pendingRemoval.contains(scene))
135 { this.pendingRemoval.push(scene); }
137 136 }
138 137 }
139 138
@@ -168,15 +167,15 @@ class Game
168 167 {
169 168 if (this.pendingRemoval.length > 0)
170 169 {
171 this.pendingRemoval.sort((a, b) => a - b);
172
173 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
170 for (let i = 0; i < this.pendingRemoval.length; i++)
174 171 {
175 if (this.activeScenes[this.pendingRemoval[i]].destroyed)
176 { this.activeScenes.removeAt(this.pendingRemoval[i]); }
177
178 this.pendingRemoval.splice(i, 1);
172 const scene = this.pendingRemoval[i];
173 const index = this.activeScenes.indexOf(scene);
174 if (index >= 0 && scene.destroyed)
175 { this.activeScenes.removeAt(index); }
179 176 }
177
178 this.pendingRemoval.length = 0;
180 179 }
181 180 }
182 181 }
@@ -129,11 +129,10 @@ class Game
129
129
130 removeScene (scene)
130 removeScene (scene)
131 {
131 {
132 const index = this.activeScenes.indexOf(scene);
132 if (this.activeScenes.indexOf(scene) >= 0)
133 if (index >= 0 && !scene.destroyed)
134 {
133 {
135 if (!this.pendingRemoval.contains(index))
134 if (!this.pendingRemoval.contains(scene))
136 { this.pendingRemoval.push(index); }
135 { this.pendingRemoval.push(scene); }
137 }
136 }
138 }
137 }
139
138
@@ -168,15 +167,15 @@ class Game
168 {
167 {
169 if (this.pendingRemoval.length > 0)
168 if (this.pendingRemoval.length > 0)
170 {
169 {
171 this.pendingRemoval.sort((a, b) => a - b);
170 for (let i = 0; i < this.pendingRemoval.length; i++)
172
173 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
174 {
171 {
175 if (this.activeScenes[this.pendingRemoval[i]].destroyed)
172 const scene = this.pendingRemoval[i];
176 { this.activeScenes.removeAt(this.pendingRemoval[i]); }
173 const index = this.activeScenes.indexOf(scene);
177
174 if (index >= 0 && scene.destroyed)
178 this.pendingRemoval.splice(i, 1);
175 { this.activeScenes.removeAt(index); }
179 }
176 }
177
178 this.pendingRemoval.length = 0;
180 }
179 }
181 }
180 }
182}
181}
framework/engine/gameobject.js +13 −8
@@ -25,14 +25,14 @@ class GameObject
25 25 checkQuadtree ()
26 26 {
27 27 if (!this.quadTree)
28 {return;}
28 { return; }
29 29
30 30 if (this.node)
31 31 {
32 32 if (this.transform.position.x < this.node.x1
33 || this.transform.position.x > this.node.x2
34 || this.transform.position.y < this.node.y1
35 || this.transform.position.y > this.node.y2)
33 || this.transform.position.x > this.node.x2
34 || this.transform.position.y < this.node.y1
35 || this.transform.position.y > this.node.y2)
36 36 {
37 37 this.quadTree.remove(this);
38 38 this.quadTree.add(this);
@@ -46,12 +46,14 @@ class GameObject
46 46
47 47 update (deltaTime)
48 48 {
49 if (this.destroyed)
50 { return; }
51
49 52 this.transform.update(deltaTime);
50 53 this.collider.update(deltaTime);
51 54 this.renderer.update(deltaTime);
52 55
53 if (!this.destroyed)
54 {this.checkQuadtree();}
56 this.checkQuadtree();
55 57 }
56 58
57 59 destroy ()
@@ -60,13 +62,16 @@ class GameObject
60 62 {
61 63 this.onDestroy && this.onDestroy();
62 64 this.quadTree && this.quadTree.remove(this);
63 this.scene.removeObject(this);
65 this.scene && this.scene.removeObject(this);
64 66 this.destroyed = true;
65 67 }
66 68 }
67 69
68 70 draw ()
69 71 {
72 if (this.destroyed)
73 { return; }
74
70 75 this.renderer.draw();
71 76 }
72 }
77 }
@@ -25,14 +25,14 @@ class GameObject
25 checkQuadtree ()
25 checkQuadtree ()
26 {
26 {
27 if (!this.quadTree)
27 if (!this.quadTree)
28 {return;}
28 { return; }
29
29
30 if (this.node)
30 if (this.node)
31 {
31 {
32 if (this.transform.position.x < this.node.x1
32 if (this.transform.position.x < this.node.x1
33 || this.transform.position.x > this.node.x2
33 || this.transform.position.x > this.node.x2
34 || this.transform.position.y < this.node.y1
34 || this.transform.position.y < this.node.y1
35 || this.transform.position.y > this.node.y2)
35 || this.transform.position.y > this.node.y2)
36 {
36 {
37 this.quadTree.remove(this);
37 this.quadTree.remove(this);
38 this.quadTree.add(this);
38 this.quadTree.add(this);
@@ -46,12 +46,14 @@ class GameObject
46
46
47 update (deltaTime)
47 update (deltaTime)
48 {
48 {
49 if (this.destroyed)
50 { return; }
51
49 this.transform.update(deltaTime);
52 this.transform.update(deltaTime);
50 this.collider.update(deltaTime);
53 this.collider.update(deltaTime);
51 this.renderer.update(deltaTime);
54 this.renderer.update(deltaTime);
52
55
53 if (!this.destroyed)
56 this.checkQuadtree();
54 {this.checkQuadtree();}
55 }
57 }
56
58
57 destroy ()
59 destroy ()
@@ -60,13 +62,16 @@ class GameObject
60 {
62 {
61 this.onDestroy && this.onDestroy();
63 this.onDestroy && this.onDestroy();
62 this.quadTree && this.quadTree.remove(this);
64 this.quadTree && this.quadTree.remove(this);
63 this.scene.removeObject(this);
65 this.scene && this.scene.removeObject(this);
64 this.destroyed = true;
66 this.destroyed = true;
65 }
67 }
66 }
68 }
67
69
68 draw ()
70 draw ()
69 {
71 {
72 if (this.destroyed)
73 { return; }
74
70 this.renderer.draw();
75 this.renderer.draw();
71 }
76 }
72}
77}
framework/engine/image.js +5 −3
@@ -23,9 +23,11 @@ class image
23 23 this.cacheWidth = -1;
24 24 this.cacheHeight = -1;
25 25
26 image.id = "loadedImage";
27 document.body.append(image);
28 console.log("Image loaded: " + image.src);
26 // Keep the Image out of the DOM — canvas can draw from it directly.
27 if (image && image.style)
28 { image.style.display = "none"; }
29
30 console.log("Image loaded: " + (image && image.src ? image.src : ""));
29 31 }
30 32
31 33 draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)
@@ -23,9 +23,11 @@ class image
23 this.cacheWidth = -1;
23 this.cacheWidth = -1;
24 this.cacheHeight = -1;
24 this.cacheHeight = -1;
25
25
26 image.id = "loadedImage";
26 // Keep the Image out of the DOM — canvas can draw from it directly.
27 document.body.append(image);
27 if (image && image.style)
28 console.log("Image loaded: " + image.src);
28 { image.style.display = "none"; }
29
30 console.log("Image loaded: " + (image && image.src ? image.src : ""));
29 }
31 }
30
32
31 draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)
33 draw (scene, dx, dy, dw, dh, rotation, mirrorX, mirrorY, alpha, subImage)
framework/engine/objectComponents/collider.js +3 −1
@@ -40,7 +40,9 @@ class Collider
40 40 { return; }
41 41
42 42 var hit = false;
43 var clickPos = GameInput.mousePosition.subtract(this.gameObject.scene.position).subtract(this.gameObject.scene.cameraPosition);
43 var clickPos = GameInput.mousePosition
44 .subtract(this.gameObject.scene.real_position)
45 .subtract(this.gameObject.scene.cameraPosition);
44 46
45 47 var hw = this.gameObject.transform.size.x / 2;
46 48 var hh = this.gameObject.transform.size.y / 2;
@@ -40,7 +40,9 @@ class Collider
40 { return; }
40 { return; }
41
41
42 var hit = false;
42 var hit = false;
43 var clickPos = GameInput.mousePosition.subtract(this.gameObject.scene.position).subtract(this.gameObject.scene.cameraPosition);
43 var clickPos = GameInput.mousePosition
44 .subtract(this.gameObject.scene.real_position)
45 .subtract(this.gameObject.scene.cameraPosition);
44
46
45 var hw = this.gameObject.transform.size.x / 2;
47 var hw = this.gameObject.transform.size.x / 2;
46 var hh = this.gameObject.transform.size.y / 2;
48 var hh = this.gameObject.transform.size.y / 2;
framework/engine/objectComponents/transform.js +20 −3
@@ -62,9 +62,26 @@ class Transform
62 62
63 63 get size ()
64 64 {
65 return new vector(
66 this.scale.x * this.gameObject.renderer.sprite.width,
67 this.scale.y * this.gameObject.renderer.sprite.height);
65 const sprite = this.gameObject.renderer && this.gameObject.renderer.sprite;
66 const width = sprite ? sprite.width : 0;
67 const height = sprite ? sprite.height : 0;
68
69 if (!this.g_size)
70 { this.g_size = new vector(0, 0); }
71
72 this.g_size.x = this.scale.x * width;
73 this.g_size.y = this.scale.y * height;
74 return this.g_size;
75 }
76
77 set size (v)
78 {
79 const sprite = this.gameObject.renderer && this.gameObject.renderer.sprite;
80 const width = sprite && sprite.width ? sprite.width : 1;
81 const height = sprite && sprite.height ? sprite.height : 1;
82
83 this.scale.x = v.x / width;
84 this.scale.y = v.y / height;
68 85 }
69 86
70 87 constructor (gameObject, x, y, w, h, r)
@@ -62,9 +62,26 @@ class Transform
62
62
63 get size ()
63 get size ()
64 {
64 {
65 return new vector(
65 const sprite = this.gameObject.renderer && this.gameObject.renderer.sprite;
66 this.scale.x * this.gameObject.renderer.sprite.width,
66 const width = sprite ? sprite.width : 0;
67 this.scale.y * this.gameObject.renderer.sprite.height);
67 const height = sprite ? sprite.height : 0;
68
69 if (!this.g_size)
70 { this.g_size = new vector(0, 0); }
71
72 this.g_size.x = this.scale.x * width;
73 this.g_size.y = this.scale.y * height;
74 return this.g_size;
75 }
76
77 set size (v)
78 {
79 const sprite = this.gameObject.renderer && this.gameObject.renderer.sprite;
80 const width = sprite && sprite.width ? sprite.width : 1;
81 const height = sprite && sprite.height ? sprite.height : 1;
82
83 this.scale.x = v.x / width;
84 this.scale.y = v.y / height;
68 }
85 }
69
86
70 constructor (gameObject, x, y, w, h, r)
87 constructor (gameObject, x, y, w, h, r)
framework/engine/scene.js +57 −24
@@ -74,31 +74,62 @@ class Scene
74 74
75 75 destroy ()
76 76 {
77 if (!this.destroyed)
77 if (this.destroyed)
78 { return; }
79
80 for (var i = 0; i < this.activeObjects.length; i++)
78 81 {
79 for (var i = 0; i < this.activeObjects.length; i++)
80 {
81 this.activeObjects[i].destroy();
82 }
83 this.game.removeScene(this);
82 this.activeObjects[i].destroy();
83 }
84 84
85 //this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
85 this.destroyed = true;
86 86
87 this.removeCanvas();
87 if (this.game)
88 { this.game.removeScene(this); }
88 89
89 if (this.primary && this.parentScene)
90 this.removeCanvas();
91
92 if (this.primary)
93 {
94 if (this.parentScene && !this.parentScene.destroyed)
90 95 {
91 96 this.parentScene.setPrimary();
92 97 }
93
94 this.destroyed = true;
98 else if (this.game)
99 {
100 let promoted = null;
101 for (let i = 0; i < this.game.activeScenes.length; i++)
102 {
103 const candidate = this.game.activeScenes[i];
104 if (candidate !== this && !candidate.destroyed)
105 {
106 promoted = candidate;
107 break;
108 }
109 }
110
111 if (promoted)
112 { this.game.setPrimaryScene(promoted); }
113 else
114 { this.g_primary = false; }
115 }
116 else
117 {
118 this.g_primary = false;
119 }
95 120 }
96 121 }
97 122
98 123 removeCanvas ()
99 124 {
100 var elem = document.getElementById(this.id);
101 return elem.parentNode.removeChild(elem);
125 var elem = this.cv_canvas || document.getElementById(this.id);
126 if (elem && elem.parentNode)
127 {
128 elem.parentNode.removeChild(elem);
129 }
130
131 this.cv_canvas = null;
132 this.cv_context = null;
102 133 }
103 134
104 135 backgroundColor =
@@ -135,11 +166,10 @@ class Scene
135 166
136 167 removeObject (obj)
137 168 {
138 const index = this.activeObjects.indexOf(obj);
139 if (index >= 0 && !obj.destroyed)
169 if (this.activeObjects.indexOf(obj) >= 0)
140 170 {
141 if (!this.pendingRemoval.contains(index))
142 { this.pendingRemoval.push(index); }
171 if (!this.pendingRemoval.contains(obj))
172 { this.pendingRemoval.push(obj); }
143 173 }
144 174
145 175 if (this.quadTree === obj.quadTree)
@@ -148,6 +178,9 @@ class Scene
148 178
149 179 update (deltaTime)
150 180 {
181 if (this.destroyed)
182 { return; }
183
151 184 for (let i = 0; i < this.activeObjects.length; i++)
152 185 {
153 186 this.activeObjects[i].update(deltaTime);
@@ -155,15 +188,15 @@ class Scene
155 188
156 189 if (this.pendingRemoval.length)
157 190 {
158 this.pendingRemoval.sort((a, b) => a - b);
159
160 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
191 for (let i = 0; i < this.pendingRemoval.length; i++)
161 192 {
162 if (this.activeObjects[this.pendingRemoval[i]].destroyed)
163 { this.activeObjects.removeAt(this.pendingRemoval[i]); }
164
165 this.pendingRemoval.splice(i, 1);
193 const obj = this.pendingRemoval[i];
194 const index = this.activeObjects.indexOf(obj);
195 if (index >= 0 && obj.destroyed)
196 { this.activeObjects.removeAt(index); }
166 197 }
198
199 this.pendingRemoval.length = 0;
167 200 }
168 201
169 202 this.quadTree.update(deltaTime);
@@ -74,31 +74,62 @@ class Scene
74
74
75 destroy ()
75 destroy ()
76 {
76 {
77 if (!this.destroyed)
77 if (this.destroyed)
78 { return; }
79
80 for (var i = 0; i < this.activeObjects.length; i++)
78 {
81 {
79 for (var i = 0; i < this.activeObjects.length; i++)
82 this.activeObjects[i].destroy();
80 {
83 }
81 this.activeObjects[i].destroy();
82 }
83 this.game.removeScene(this);
84
84
85 //this.context.clearRect(0, 0, this.real_size.x, this.real_size.y);
85 this.destroyed = true;
86
86
87 this.removeCanvas();
87 if (this.game)
88 { this.game.removeScene(this); }
88
89
89 if (this.primary && this.parentScene)
90 this.removeCanvas();
91
92 if (this.primary)
93 {
94 if (this.parentScene && !this.parentScene.destroyed)
90 {
95 {
91 this.parentScene.setPrimary();
96 this.parentScene.setPrimary();
92 }
97 }
93
98 else if (this.game)
94 this.destroyed = true;
99 {
100 let promoted = null;
101 for (let i = 0; i < this.game.activeScenes.length; i++)
102 {
103 const candidate = this.game.activeScenes[i];
104 if (candidate !== this && !candidate.destroyed)
105 {
106 promoted = candidate;
107 break;
108 }
109 }
110
111 if (promoted)
112 { this.game.setPrimaryScene(promoted); }
113 else
114 { this.g_primary = false; }
115 }
116 else
117 {
118 this.g_primary = false;
119 }
95 }
120 }
96 }
121 }
97
122
98 removeCanvas ()
123 removeCanvas ()
99 {
124 {
100 var elem = document.getElementById(this.id);
125 var elem = this.cv_canvas || document.getElementById(this.id);
101 return elem.parentNode.removeChild(elem);
126 if (elem && elem.parentNode)
127 {
128 elem.parentNode.removeChild(elem);
129 }
130
131 this.cv_canvas = null;
132 this.cv_context = null;
102 }
133 }
103
134
104 backgroundColor =
135 backgroundColor =
@@ -135,11 +166,10 @@ class Scene
135
166
136 removeObject (obj)
167 removeObject (obj)
137 {
168 {
138 const index = this.activeObjects.indexOf(obj);
169 if (this.activeObjects.indexOf(obj) >= 0)
139 if (index >= 0 && !obj.destroyed)
140 {
170 {
141 if (!this.pendingRemoval.contains(index))
171 if (!this.pendingRemoval.contains(obj))
142 { this.pendingRemoval.push(index); }
172 { this.pendingRemoval.push(obj); }
143 }
173 }
144
174
145 if (this.quadTree === obj.quadTree)
175 if (this.quadTree === obj.quadTree)
@@ -148,6 +178,9 @@ class Scene
148
178
149 update (deltaTime)
179 update (deltaTime)
150 {
180 {
181 if (this.destroyed)
182 { return; }
183
151 for (let i = 0; i < this.activeObjects.length; i++)
184 for (let i = 0; i < this.activeObjects.length; i++)
152 {
185 {
153 this.activeObjects[i].update(deltaTime);
186 this.activeObjects[i].update(deltaTime);
@@ -155,15 +188,15 @@ class Scene
155
188
156 if (this.pendingRemoval.length)
189 if (this.pendingRemoval.length)
157 {
190 {
158 this.pendingRemoval.sort((a, b) => a - b);
191 for (let i = 0; i < this.pendingRemoval.length; i++)
159
160 for (let i = this.pendingRemoval.length - 1; i >= 0; i--)
161 {
192 {
162 if (this.activeObjects[this.pendingRemoval[i]].destroyed)
193 const obj = this.pendingRemoval[i];
163 { this.activeObjects.removeAt(this.pendingRemoval[i]); }
194 const index = this.activeObjects.indexOf(obj);
164
195 if (index >= 0 && obj.destroyed)
165 this.pendingRemoval.splice(i, 1);
196 { this.activeObjects.removeAt(index); }
166 }
197 }
198
199 this.pendingRemoval.length = 0;
167 }
200 }
168
201
169 this.quadTree.update(deltaTime);
202 this.quadTree.update(deltaTime);
framework/util/particleEmitter.js +10 −5
@@ -82,7 +82,7 @@ class ParticleEmitter
82 82 this.acceleration.y, this.angularAcceleration, this.sprite, this.startSize.x,
83 83 this.startSize.y, this.endSize.x, this.endSize.y, this.lifetimeMin,
84 84 this.lifetimeMax, this.fadeIn, this.fadeOut, this.startFrame, this.animationSpeed,
85 this.friction, this.angularFriction);
85 this.friction.getCopy(), this.angularFriction);
86 86 }
87 87 }
88 88
@@ -97,7 +97,8 @@ class ParticleEmitter
97 97 this.emit();
98 98 }
99 99
100 for (let i = 0; i < this.mine.length; i++)
100 // Backwards so dispose()/remove during update cannot skip particles.
101 for (let i = this.mine.length - 1; i >= 0; i--)
101 102 {
102 103 this.mine[i].update(deltaTime);
103 104 }
@@ -193,7 +194,7 @@ class Particle
193 194 this.animationSpeed = as;
194 195 this.animTimer = as;
195 196 this.subImage = sf;
196 this.friction = fric;
197 this.friction = fric ? fric.getCopy() : new vector(0, 0);
197 198 this.angularFriction = anfric;
198 199 }
199 200
@@ -234,9 +235,13 @@ class Particle
234 235
235 236 draw (scene)
236 237 {
237 const foAlpha = Math.min(1, this.lifeTime / this.fadeOutTime);
238 const foAlpha = this.fadeOutTime > 0
239 ? Math.min(1, this.lifeTime / this.fadeOutTime)
240 : 1;
238 241
239 const fiAlpha = 1 - (this.fadeInTime / this.fadeInStart);
242 const fiAlpha = this.fadeInStart > 0
243 ? 1 - (this.fadeInTime / this.fadeInStart)
244 : 1;
240 245
241 246 this.sprite.draw(
242 247 scene,
@@ -82,7 +82,7 @@ class ParticleEmitter
82 this.acceleration.y, this.angularAcceleration, this.sprite, this.startSize.x,
82 this.acceleration.y, this.angularAcceleration, this.sprite, this.startSize.x,
83 this.startSize.y, this.endSize.x, this.endSize.y, this.lifetimeMin,
83 this.startSize.y, this.endSize.x, this.endSize.y, this.lifetimeMin,
84 this.lifetimeMax, this.fadeIn, this.fadeOut, this.startFrame, this.animationSpeed,
84 this.lifetimeMax, this.fadeIn, this.fadeOut, this.startFrame, this.animationSpeed,
85 this.friction, this.angularFriction);
85 this.friction.getCopy(), this.angularFriction);
86 }
86 }
87 }
87 }
88
88
@@ -97,7 +97,8 @@ class ParticleEmitter
97 this.emit();
97 this.emit();
98 }
98 }
99
99
100 for (let i = 0; i < this.mine.length; i++)
100 // Backwards so dispose()/remove during update cannot skip particles.
101 for (let i = this.mine.length - 1; i >= 0; i--)
101 {
102 {
102 this.mine[i].update(deltaTime);
103 this.mine[i].update(deltaTime);
103 }
104 }
@@ -193,7 +194,7 @@ class Particle
193 this.animationSpeed = as;
194 this.animationSpeed = as;
194 this.animTimer = as;
195 this.animTimer = as;
195 this.subImage = sf;
196 this.subImage = sf;
196 this.friction = fric;
197 this.friction = fric ? fric.getCopy() : new vector(0, 0);
197 this.angularFriction = anfric;
198 this.angularFriction = anfric;
198 }
199 }
199
200
@@ -234,9 +235,13 @@ class Particle
234
235
235 draw (scene)
236 draw (scene)
236 {
237 {
237 const foAlpha = Math.min(1, this.lifeTime / this.fadeOutTime);
238 const foAlpha = this.fadeOutTime > 0
239 ? Math.min(1, this.lifeTime / this.fadeOutTime)
240 : 1;
238
241
239 const fiAlpha = 1 - (this.fadeInTime / this.fadeInStart);
242 const fiAlpha = this.fadeInStart > 0
243 ? 1 - (this.fadeInTime / this.fadeInStart)
244 : 1;
240
245
241 this.sprite.draw(
246 this.sprite.draw(
242 scene,
247 scene,
framework/util/signal.js +3 −3
@@ -11,7 +11,7 @@ class Signal
11 11 this.listeners[i].callback.apply(this.listeners[i].context, arguments);
12 12 }
13 13
14 for (var i = this.listeners.length - 1; i > 0; i--)
14 for (var i = this.listeners.length - 1; i >= 0; i--)
15 15 {
16 16 if (this.listeners[i].once)
17 17 {
@@ -35,7 +35,7 @@ class Signal
35 35
36 36 contains (callback, context)
37 37 {
38 for (var i = this.listeners.length - 1; i > 0; i--)
38 for (var i = this.listeners.length - 1; i >= 0; i--)
39 39 {
40 40 if (this.listeners[i].callback === callback && this.listeners[i].context === context)
41 41 {
@@ -48,7 +48,7 @@ class Signal
48 48
49 49 remove (callback, context)
50 50 {
51 for (var i = this.listeners.length - 1; i > 0; i--)
51 for (var i = this.listeners.length - 1; i >= 0; i--)
52 52 {
53 53 if (this.listeners[i].callback === callback && this.listeners[i].context === context)
54 54 {
@@ -11,7 +11,7 @@ class Signal
11 this.listeners[i].callback.apply(this.listeners[i].context, arguments);
11 this.listeners[i].callback.apply(this.listeners[i].context, arguments);
12 }
12 }
13
13
14 for (var i = this.listeners.length - 1; i > 0; i--)
14 for (var i = this.listeners.length - 1; i >= 0; i--)
15 {
15 {
16 if (this.listeners[i].once)
16 if (this.listeners[i].once)
17 {
17 {
@@ -35,7 +35,7 @@ class Signal
35
35
36 contains (callback, context)
36 contains (callback, context)
37 {
37 {
38 for (var i = this.listeners.length - 1; i > 0; i--)
38 for (var i = this.listeners.length - 1; i >= 0; i--)
39 {
39 {
40 if (this.listeners[i].callback === callback && this.listeners[i].context === context)
40 if (this.listeners[i].callback === callback && this.listeners[i].context === context)
41 {
41 {
@@ -48,7 +48,7 @@ class Signal
48
48
49 remove (callback, context)
49 remove (callback, context)
50 {
50 {
51 for (var i = this.listeners.length - 1; i > 0; i--)
51 for (var i = this.listeners.length - 1; i >= 0; i--)
52 {
52 {
53 if (this.listeners[i].callback === callback && this.listeners[i].context === context)
53 if (this.listeners[i].callback === callback && this.listeners[i].context === context)
54 {
54 {
framework/util/urlParams.js +3 −2
@@ -15,6 +15,7 @@ var UrlParams =
15 15 var url = new URL(url_string);
16 16 url.searchParams.set(key, value);
17 17
18 window.history.pushState(null, {}, url);
18 // replaceState avoids flooding history when params change often.
19 window.history.replaceState(null, "", url);
19 20 }
20 };
21 };
@@ -15,6 +15,7 @@ var UrlParams =
15 var url = new URL(url_string);
15 var url = new URL(url_string);
16 url.searchParams.set(key, value);
16 url.searchParams.set(key, value);
17
17
18 window.history.pushState(null, {}, url);
18 // replaceState avoids flooding history when params change often.
19 window.history.replaceState(null, "", url);
19 }
20 }
20};
21};