Skip to content

Commit c2bf4fa

Browse files
committed
fix(Migration): Stacks freezing
Prevent error messages from blocked stacks
1 parent 4f57a05 commit c2bf4fa

File tree

2 files changed

+155
-107
lines changed

2 files changed

+155
-107
lines changed

lib/AnimationFrame.ts

Lines changed: 154 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -77,61 +77,96 @@ class AnimationFrame implements IAnimationFrame {
7777
},
7878
params: Array<any> = [],
7979
ID?: string): boolean|string {
80-
return this.parallelSubscribe({
81-
context,
82-
callback,
83-
params,
84-
ID,
85-
});
80+
try {
81+
return this.parallelSubscribe({
82+
context,
83+
callback,
84+
params,
85+
ID,
86+
});
87+
} catch (e) {
88+
this._errorHandler(e);
89+
try {
90+
return root._AnimationFrame.parallelSubscribe({
91+
context,
92+
callback,
93+
params,
94+
ID,
95+
});
96+
} catch (e) {
97+
this._errorHandler(e);
98+
return false;
99+
}
100+
}
86101
}
87102

88103
/**
89104
* Parallel callback subscribe
90-
* @param _params
105+
* @param params
91106
* @return {boolean|string}
92107
*/
93-
public parallelSubscribe(_params): boolean|string {
94-
_params = this.prepareParams(_params);
95-
if (_params) {
96-
/**
97-
* Add method to the stack
98-
*/
99-
this.parallelStack[_params.ID] = {
100-
callback: _params.callback,
101-
context: _params.context,
102-
params: _params.params,
103-
};
104-
/**
105-
* Return subscription ID
106-
*/
107-
return _params.ID;
108-
} else {
109-
return false;
108+
public parallelSubscribe(params): boolean|string {
109+
try {
110+
let _params: any = this.prepareParams(params);
111+
if (_params) {
112+
/**
113+
* Add method to the stack
114+
*/
115+
this.parallelStack[_params.ID] = {
116+
callback: _params.callback,
117+
context: _params.context,
118+
params: _params.params,
119+
};
120+
/**
121+
* Return subscription ID
122+
*/
123+
return _params.ID;
124+
} else {
125+
return false;
126+
}
127+
} catch (e) {
128+
this._errorHandler(e);
129+
try {
130+
return root._AnimationFrame.parallelSubscribe(params);
131+
} catch (e) {
132+
this._errorHandler(e);
133+
return false;
134+
}
110135
}
111136
}
112137

113138
/**
114139
* Serial callback subscribe
115-
* @param _params
140+
* @param params
116141
* @return {boolean|string}
117142
*/
118-
public serialSubscribe(_params): boolean|string {
119-
_params = this.prepareParams(_params);
120-
if (_params) {
121-
/**
122-
* Add method to the stack
123-
*/
124-
this.serialStack[_params.ID] = {
125-
callback: _params.callback,
126-
context: _params.context,
127-
params: _params.params,
128-
};
129-
/**
130-
* Return subscription ID
131-
*/
132-
return _params.ID;
133-
} else {
134-
return false;
143+
public serialSubscribe(params): boolean|string {
144+
try {
145+
let _params: any = this.prepareParams(params);
146+
if (_params) {
147+
/**
148+
* Add method to the stack
149+
*/
150+
this.serialStack[_params.ID] = {
151+
callback: _params.callback,
152+
context: _params.context,
153+
params: _params.params,
154+
};
155+
/**
156+
* Return subscription ID
157+
*/
158+
return _params.ID;
159+
} else {
160+
return false;
161+
}
162+
} catch (e) {
163+
this._errorHandler(e);
164+
try {
165+
return root._AnimationFrame.serialSubscribe(params);
166+
} catch (e) {
167+
this._errorHandler(e);
168+
return false;
169+
}
135170
}
136171
}
137172

@@ -140,49 +175,79 @@ class AnimationFrame implements IAnimationFrame {
140175
* @param ID
141176
*/
142177
public unsubscribe(ID: string): boolean {
143-
return this.parallelUnsubscribe(ID);
178+
try {
179+
return this.parallelUnsubscribe(ID);
180+
} catch (e) {
181+
this._errorHandler(e);
182+
try {
183+
return root._AnimationFrame.parallelUnsubscribe(ID);
184+
} catch (e) {
185+
this._errorHandler(e);
186+
return false;
187+
}
188+
}
144189
}
145190

146191
/**
147192
* Parallel callback unsubscribe
148193
* @param ID
149194
*/
150195
public parallelUnsubscribe(ID: string): boolean {
151-
if (typeof ID === "string") {
152-
/**
153-
* If required method exist in the stack
154-
*/
155-
if (this.parallelStack[ID]) {
196+
try {
197+
if (typeof ID === "string") {
156198
/**
157-
* Nullify method in the stack and destroy it
199+
* If required method exist in the stack
158200
*/
159-
this.parallelStack[ID] = false;
160-
delete this.parallelStack[ID];
161-
return true;
201+
if (this.parallelStack[ID]) {
202+
/**
203+
* Nullify method in the stack and destroy it
204+
*/
205+
this.parallelStack[ID] = false;
206+
delete this.parallelStack[ID];
207+
return true;
208+
}
209+
}
210+
return false;
211+
} catch (e) {
212+
this._errorHandler(e);
213+
try {
214+
return root._AnimationFrame.parallelUnsubscribe(ID);
215+
} catch (e) {
216+
this._errorHandler(e);
217+
return false;
162218
}
163219
}
164-
return false;
165220
}
166221

167222
/**
168223
* Serial callback unsubscribe method by ID
169224
* @param ID
170225
*/
171226
public serialUnsubscribe(ID: string): boolean {
172-
if (typeof ID === "string") {
173-
/**
174-
* If required method exist in the stack
175-
*/
176-
if (this.serialStack[ID]) {
227+
try {
228+
if (typeof ID === "string") {
177229
/**
178-
* Nullify method in the stack and destroy it
230+
* If required method exist in the stack
179231
*/
180-
this.serialStack[ID] = false;
181-
delete this.serialStack[ID];
182-
return true;
232+
if (this.serialStack[ID]) {
233+
/**
234+
* Nullify method in the stack and destroy it
235+
*/
236+
this.serialStack[ID] = false;
237+
delete this.serialStack[ID];
238+
return true;
239+
}
240+
}
241+
return false;
242+
} catch (e) {
243+
this._errorHandler(e);
244+
try {
245+
return root._AnimationFrame.serialUnsubscribe(ID);
246+
} catch (e) {
247+
this._errorHandler(e);
248+
return false;
183249
}
184250
}
185-
return false;
186251
}
187252

188253
/**
@@ -234,23 +299,23 @@ class AnimationFrame implements IAnimationFrame {
234299
*/
235300
public watch(): void {
236301
try {
237-
this.parallelWatch();
238-
} catch (e) {
239-
if (this.errorHandler) {
240-
this.errorHandler(e);
302+
try {
303+
this.parallelWatch();
304+
} catch (e) {
305+
this._errorHandler(e);
241306
}
242-
}
243-
try {
244-
this.serialWatch();
245-
} catch (e) {
246-
if (this.errorHandler) {
247-
this.errorHandler(e);
307+
try {
308+
this.serialWatch();
309+
} catch (e) {
310+
this._errorHandler(e);
248311
}
312+
/**
313+
* Recall watcher
314+
*/
315+
root.requestAnimationFrame(this.watch.bind(this));
316+
} catch (e) {
317+
this._errorHandler(e);
249318
}
250-
/**
251-
* Recall watcher
252-
*/
253-
root.requestAnimationFrame(this.watch.bind(this));
254319
}
255320

256321
/**
@@ -309,17 +374,13 @@ class AnimationFrame implements IAnimationFrame {
309374
}
310375

311376
} catch (e) {
312-
if (this.errorHandler) {
313-
this.errorHandler(e);
314-
}
377+
this._errorHandler(e);
315378
}
316379
}
317380
}
318381
}
319382
} catch (e) {
320-
if (this.errorHandler) {
321-
this.errorHandler(e);
322-
}
383+
this._errorHandler(e);
323384
}
324385
}
325386

@@ -386,9 +447,16 @@ class AnimationFrame implements IAnimationFrame {
386447
}
387448
}
388449
} catch (e) {
389-
if (this.errorHandler) {
390-
this.errorHandler(e);
391-
}
450+
this._errorHandler(e);
451+
}
452+
}
453+
454+
/**
455+
* Error Handler
456+
*/
457+
public _errorHandler(e) {
458+
if (this.errorHandler) {
459+
this.errorHandler(e);
392460
}
393461
}
394462
}

webpack.build.config.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,7 @@ module.exports = {
166166
test: /\.json$/,
167167
loaders: [
168168
StringReplacePlugin.replace({
169-
replacements: [
170-
{
171-
pattern: /#HASH#/gi,
172-
replacement: () => {
173-
return crypto.createHash("md5").update(
174-
packagenpm.version).digest("hex");
175-
}
176-
},
177-
{
178-
pattern: /#PACKAGE_NAME#/gi,
179-
replacement: () => {
180-
return packagenpm.name;
181-
}
182-
},
183-
{
184-
pattern: /#PACKAGE_VERSION#/gi,
185-
replacement: () => {
186-
return packagenpm.version;
187-
}
188-
}
189-
]
169+
replacements: replacements
190170
}),
191171
"json-loader"
192172
]

0 commit comments

Comments
 (0)