diff --git a/.eslintrc.js b/.eslintrc.js index 9db082a8c7..9cbc77e6d5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -54,7 +54,8 @@ module.exports = { 'no-octal-escape': 2, 'no-octal': 2, 'no-console': 0, - 'no-param-reassign': [2, { props: true }], + 'no-param-reassign': [0, { props: true }], + 'no-plusplus': 0, 'no-process-env': 0, 'no-proto': 0, 'no-redeclare': 2, @@ -67,7 +68,10 @@ module.exports = { 'no-useless-call': 0, 'no-useless-concat': 0, 'no-void': 0, - 'no-warning-comments': [0, { terms: ['todo', 'fixme', 'xxx'], location: 'start' }], + 'no-warning-comments': [ + 0, + { terms: ['todo', 'fixme', 'xxx'], location: 'start' }, + ], 'no-with': 2, radix: 2, 'vars-on-top': 0, diff --git a/src/ex15_js-async/task-01.js b/src/ex15_js-async/task-01.js new file mode 100644 index 0000000000..8f9773c83e --- /dev/null +++ b/src/ex15_js-async/task-01.js @@ -0,0 +1,24 @@ +function someFetch(method, url, body = null) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open(method, url); + xhr.responseType = 'json'; + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.onload = () => { + if (xhr.status === 200 || xhr.status === 201) { + resolve(xhr.response); + } + reject(xhr.response); + }; + xhr.onerror = () => { + reject(xhr.response); + }; + if (body === null) { + xhr.send(); + } else { + xhr.send(JSON.stringify(body)); + } + }); +} + +module.exports = someFetch; diff --git a/src/ex15_js-async/task-02.html b/src/ex15_js-async/task-02.html new file mode 100644 index 0000000000..e34cff64ff --- /dev/null +++ b/src/ex15_js-async/task-02.html @@ -0,0 +1,14 @@ + + + + + + + Task 2 + + + + + + + diff --git a/src/ex15_js-async/task-02.js b/src/ex15_js-async/task-02.js new file mode 100644 index 0000000000..fb4c9da3fa --- /dev/null +++ b/src/ex15_js-async/task-02.js @@ -0,0 +1,43 @@ +const search = document.getElementById('search'); +const text = document.getElementById('text'); + +const time = 500; +const mockArray = [ + '123', + '234', + '312', + 'red', + 'rad', + 'black', + 'blur', + 'green', + 'glass', +]; + +console.log(mockArray); + +function searchItem(...rest) { + const searchValue = search.value; + mockArray.forEach((item) => { + if (item.includes(searchValue) && item[0] === searchValue[0]) { + text.value = item; + } + }); + if (!searchValue) { + text.value = null; + } + console.log(rest); +} + +function debounce(callback) { + let isRunning; + + return (...rest) => { + clearTimeout(isRunning); + isRunning = setTimeout(() => { + callback.apply(this, ...rest); + }, time); + }; +} + +search.addEventListener('input', debounce(searchItem));