Skip to content

Commit ca216d0

Browse files
author
Anatoly Ostrovsky
committed
Cont test and lint fixes
1 parent 38864c9 commit ca216d0

File tree

7 files changed

+55
-37
lines changed

7 files changed

+55
-37
lines changed

@types/services/http/http.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,7 @@ export function http(
174174
export const Http: Readonly<{
175175
OK: 200;
176176
MultipleChoices: 300;
177+
BadRequest: 400;
177178
NotFound: 404;
179+
ErrorMax: 599;
178180
}>;

src/animations/animate-css-driver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ export function AnimateCssDriverProvider($$animationProvider) {
244244
return runner;
245245

246246
function endFn() {
247-
animationRunners.forEach((runner) => {
248-
runner.end();
247+
animationRunners.forEach((runnerItem) => {
248+
runnerItem.end();
249249
});
250250
}
251251
},

src/directive/http/http.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -182,33 +182,39 @@ export function createHttpDirective(method, attrName) {
182182
*
183183
* @param {string | Object} html - The HTML string or object returned from the server.
184184
* @param {import("./interface.ts").SwapModeType} swap
185-
* @param {ng.Scope} scope
186-
* @param {ng.Attributes} attrs
187-
* @param {Element} element
185+
* @param {ng.Scope} scopeParam
186+
* @param {ng.Attributes} attrsParam
187+
* @param {Element} elmenetParam
188188
*/
189-
function handleSwapResponse(html, swap, scope, attrs, element) {
189+
function handleSwapResponse(
190+
html,
191+
swap,
192+
scopeParam,
193+
attrsParam,
194+
elmenetParam,
195+
) {
190196
let animationEnabled = false;
191197

192-
if (attrs.animate) {
198+
if (attrsParam.animate) {
193199
animationEnabled = true;
194200
}
195201
let nodes = [];
196202

197203
if (!["textcontent", "delete", "none"].includes(swap)) {
198204
if (!html) return;
199-
const compiled = $compile(html)(scope);
205+
const compiled = $compile(html)(scopeParam);
200206

201207
nodes =
202208
compiled instanceof DocumentFragment
203209
? Array.from(compiled.childNodes)
204210
: [compiled];
205211
}
206212

207-
const targetSelector = attrs.target;
213+
const targetSelector = attrsParam.target;
208214

209215
const target = targetSelector
210216
? document.querySelector(targetSelector)
211-
: element;
217+
: elmenetParam;
212218

213219
if (!target) {
214220
$log.warn(`${attrName}: target "${targetSelector}" not found`);
@@ -256,10 +262,10 @@ export function createHttpDirective(method, attrName) {
256262
}
257263

258264
content = insertedNodes;
259-
scope.$flushQueue(); // flush once after all insertions
265+
scopeParam.$flushQueue(); // flush once after all insertions
260266
});
261267

262-
scope.$flushQueue(); // flush leave animation
268+
scopeParam.$flushQueue(); // flush leave animation
263269
break;
264270
}
265271

@@ -268,10 +274,10 @@ export function createHttpDirective(method, attrName) {
268274
$animate.leave(target).done(() => {
269275
target.textContent = html;
270276
$animate.enter(target, target.parentNode);
271-
scope.$flushQueue();
277+
scopeParam.$flushQueue();
272278
});
273279

274-
scope.$flushQueue();
280+
scopeParam.$flushQueue();
275281
} else {
276282
target.textContent = html;
277283
}
@@ -290,7 +296,7 @@ export function createHttpDirective(method, attrName) {
290296
}
291297
});
292298

293-
if (animationEnabled) scope.$flushQueue();
299+
if (animationEnabled) scopeParam.$flushQueue();
294300
break;
295301
}
296302

@@ -305,7 +311,7 @@ export function createHttpDirective(method, attrName) {
305311
}
306312
});
307313

308-
if (animationEnabled) scope.$flushQueue();
314+
if (animationEnabled) scopeParam.$flushQueue();
309315
break;
310316
}
311317

@@ -318,7 +324,7 @@ export function createHttpDirective(method, attrName) {
318324
}
319325
});
320326

321-
if (animationEnabled) scope.$flushQueue();
327+
if (animationEnabled) scopeParam.$flushQueue();
322328
break;
323329
}
324330

@@ -336,17 +342,17 @@ export function createHttpDirective(method, attrName) {
336342
}
337343
});
338344

339-
if (animationEnabled) scope.$flushQueue();
345+
if (animationEnabled) scopeParam.$flushQueue();
340346
break;
341347
}
342348

343349
case "delete":
344350
if (animationEnabled) {
345351
$animate.leave(target).done(() => {
346352
target.remove(); // safety: actually remove in case $animate.leave didn't
347-
scope.$flushQueue();
353+
scopeParam.$flushQueue();
348354
});
349-
scope.$flushQueue();
355+
scopeParam.$flushQueue();
350356
} else {
351357
target.remove();
352358
}
@@ -362,17 +368,17 @@ export function createHttpDirective(method, attrName) {
362368
$animate.leave(content).done(() => {
363369
content = nodes[0];
364370
$animate.enter(nodes[0], target);
365-
scope.$flushQueue();
371+
scopeParam.$flushQueue();
366372
});
367-
scope.$flushQueue();
373+
scopeParam.$flushQueue();
368374
} else {
369375
content = nodes[0];
370376

371377
if (content.nodeType === Node.TEXT_NODE) {
372378
target.replaceChildren(...nodes);
373379
} else {
374380
$animate.enter(nodes[0], target);
375-
scope.$flushQueue();
381+
scopeParam.$flushQueue();
376382
}
377383
}
378384
} else {
@@ -407,15 +413,21 @@ export function createHttpDirective(method, attrName) {
407413

408414
const html = res.data;
409415

410-
if (Http.OK <= res.status && res.status <= 299) {
416+
if (
417+
Http.OK <= res.status &&
418+
res.status <= Http.MultipleChoices - 1
419+
) {
411420
if (isDefined(attrs.success)) {
412421
$parse(attrs.success)(scope, { $res: html });
413422
}
414423

415424
if (isDefined(attrs.stateSuccess)) {
416425
$state.go(attrs.stateSuccess);
417426
}
418-
} else if (400 <= res.status && res.status <= 599) {
427+
} else if (
428+
Http.BadRequest <= res.status &&
429+
res.status <= Http.ErrorMax
430+
) {
419431
if (isDefined(attrs.error)) {
420432
$parse(attrs.error)(scope, { $res: html });
421433
}

src/directive/include/include.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ export function ngIncludeDirective(
104104
// Note: We can't remove them in the cloneAttchFn of $transclude as that
105105
// function is called before linking the content, which would apply child
106106
// directives to non existing elements.
107-
const clone = $transclude(newScope, (clone) => {
107+
const clone = $transclude(newScope, (cloneParam) => {
108108
cleanupLastIncludeContent();
109109

110-
if (hasAnimate(clone)) {
111-
$animate.enter(clone, null, $element).done(afterAnimation);
110+
if (hasAnimate(cloneParam)) {
111+
$animate
112+
.enter(cloneParam, null, $element)
113+
.done(afterAnimation);
112114
} else {
113-
$element.after(clone);
115+
$element.after(cloneParam);
114116
maybeScroll();
115117
}
116118
});

src/router/state/state-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class StateProvider {
189189
try {
190190
this.stateRegistry.register(definition);
191191
} catch (err) {
192-
throw err("stateinvalid", err.message);
192+
throw stdErr("stateinvalid", err.message);
193193
}
194194

195195
return this;

src/router/url/url-matcher.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class UrlMatcher {
109109
const staticSegments = matcher._segments;
110110

111111
const pathParams = matcher._params.filter(
112-
(p) => p.location === DefType.PATH,
112+
(path) => path.location === DefType.PATH,
113113
);
114114

115115
return arrayTuples(staticSegments, pathParams.concat(undefined))
@@ -119,7 +119,7 @@ export class UrlMatcher {
119119

120120
/** @internal Given a matcher, return an array with the matcher's query params */
121121
static queryParams(matcher) {
122-
return matcher._params.filter((p) => p.location === DefType.SEARCH);
122+
return matcher._params.filter((path) => path.location === DefType.SEARCH);
123123
}
124124

125125
/**
@@ -256,13 +256,13 @@ export class UrlMatcher {
256256

257257
// Split into static segments separated by path parameter placeholders.
258258
// The number of segments is always 1 more than the number of parameters.
259-
const matchDetails = (m, isSearch) => {
259+
const matchDetails = (match, isSearch) => {
260260
// IE[78] returns '' for unmatched groups instead of null
261-
const id = m[2] || m[3];
261+
const id = match[2] || match[3];
262262

263263
const regexp = isSearch
264-
? m[4]
265-
: m[4] || (m[1] === "*" ? "[\\s\\S]*" : null);
264+
? match[4]
265+
: match[4] || (match[1] === "*" ? "[\\s\\S]*" : null);
266266

267267
const makeRegexpType = (str) =>
268268
inherit(paramTypes.type(isSearch ? "query" : "path"), {
@@ -275,7 +275,7 @@ export class UrlMatcher {
275275
return {
276276
id,
277277
regexp,
278-
segment: pattern.substring(last, m.index),
278+
segment: pattern.substring(last, match.index),
279279
type: !regexp
280280
? null
281281
: paramTypes.type(regexp) || makeRegexpType(regexp),

src/services/http/http.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ const APPLICATION_JSON = "application/json";
3131
export const Http = Object.freeze({
3232
OK: 200,
3333
MultipleChoices: 300,
34+
BadRequest: 400,
3435
NotFound: 404,
36+
ErrorMax: 599,
3537
});
3638

3739
const CONTENT_TYPE_APPLICATION_JSON = {

0 commit comments

Comments
 (0)