8000 Delint twig.loader.ajax.js · twigjs/twig.js@b913c2f · GitHub
[go: up one dir, main page]

Skip to content

Commit b913c2f

Browse files
committed
Delint twig.loader.ajax.js
1 parent 732e5dd commit b913c2f

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/twig.loader.ajax.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ module.exports = function (Twig) {
22
'use strict';
33

44
Twig.Templates.registerLoader('ajax', function (location, params, callback, errorCallback) {
5-
var template,
6-
xmlhttp,
7-
precompiled = params.precompiled,
8-
parser = this.parsers[params.parser] || this.parser.twig;
5+
let template;
6+
const {precompiled} = params;
7+
const parser = this.parsers[params.parser] || this.parser.twig;
98

10-
if (typeof XMLHttpRequest === "undefined") {
9+
if (typeof XMLHttpRequest === 'undefined') {
1110
throw new Twig.Error('Unsupported platform: Unable to do ajax requests ' +
1211
'because there is no "XMLHTTPRequest" implementation');
1312
}
1413

15-
xmlhttp = new XMLHttpRequest();
16-
xmlhttp.onreadystatechange = function() {
17-
var data = null;
14+
const xmlhttp = new XMLHttpRequest();
15+
xmlhttp.onreadystatechange = function () {
16+
let data = null;
1817

19-
if(xmlhttp.readyState === 4) {
20-
if (xmlhttp.status === 200 || (window.cordova && xmlhttp.status == 0)) {
21-
Twig.log.debug("Got template ", xmlhttp.responseText);
18+
if (xmlhttp.readyState === 4) {
19+
if (xmlhttp.status === 200 || (window.cordova && xmlhttp.status === 0)) {
20+
Twig.log.debug('Got template ', xmlhttp.responseText);
2221

2322
if (precompiled === true) {
2423
data = JSON.parse(xmlhttp.responseText);
@@ -34,22 +33,20 @@ module.exports = function (Twig) {
3433
if (typeof callback === 'function') {
3534
callback(template);
3635
}
37-
} else {
38-
if (typeof errorCallback === 'function') {
39-
errorCallback(xmlhttp);
40-
}
36+
} else if (typeof errorCallback === 'function') {
37+
errorCallback(xmlhttp);
4138
}
4239
}
4340
};
44-
xmlhttp.open("GET", location, !!params.async);
41+
42+
xmlhttp.open('GET', location, Boolean(params.async));
4543
xmlhttp.send();
4644

4745
if (params.async) {
4846
// TODO: return deferred promise
4947
return true;
50-
} else {
51-
return template;
5248
}
53-
});
5449

50+
return template;
51+
});
5552
};

0 commit comments

Comments
 (0)
0