1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-05-05 18:15:58 +02:00

eslint fixes

This commit is contained in:
Kushagra Gour 2018-11-15 19:41:03 +05:30
parent fcc2ac672c
commit 17850a15a4
3 changed files with 25 additions and 24 deletions

View File

@ -13,7 +13,7 @@ export const commandPaletteService = {
publish(eventName, ...args) {
const callbacks = this.subscriptions[eventName] || [];
callbacks.forEach(callback => {
callback.apply(null, args);
callback(...args);
});
}
};

View File

@ -1,6 +1,3 @@
import { deferred } from './deferred';
const esprima = require('esprima');
/**
* Returns the extension from the file name.
* @param {dtring} fileName File name
@ -16,13 +13,12 @@ export function getExtensionFromFileName(fileName) {
* @param {array} files Nested file structure
*/
export function linearizeFiles(files) {
function reduceToLinearFiles(files) {
return files.reduce((list, currentFile) => {
function reduceToLinearFiles(_files) {
return _files.reduce((list, currentFile) => {
if (currentFile.isFolder) {
return [...list, ...reduceToLinearFiles(currentFile.children)];
} else {
return [...list, currentFile];
}
return [...list, currentFile];
}, []);
}
return reduceToLinearFiles(files);
@ -68,7 +64,7 @@ export function getFileFromPath(files, path) {
let currentFolder = files;
const pathPieces = path.split('/');
while (pathPieces.length > 1) {
let folderName = pathPieces.shift();
const folderName = pathPieces.shift();
currentFolder = getChildFileFromName(currentFolder, folderName).file
.children;
}
@ -86,7 +82,7 @@ export function removeFileAtPath(files, path) {
let currentFolder = files;
const pathPieces = path.split('/');
while (pathPieces.length > 1) {
let folderName = pathPieces.shift();
const folderName = pathPieces.shift();
currentFolder = getChildFileFromName(currentFolder, folderName).file
.children;
}
@ -123,7 +119,7 @@ export function getParentPath(path) {
*/
export function importGithubRepo(repoUrl) {
let repoSlug, match;
if ((match = repoUrl.match(/github\.com\/([^\/]*\/[^\/]*)/))) {
if ((match = repoUrl.match(/github\.com\/([^/]*\/[^/]*)/))) {
repoSlug = match[1];
} else {
repoSlug = 'chinchang/github';
@ -141,7 +137,7 @@ export function importGithubRepo(repoUrl) {
.then(response => response.json())
.then(response => {
if (!response) {
return;
return Promise.resolve([]);
}
return Promise.all(
response.map(file => {
@ -161,6 +157,7 @@ export function importGithubRepo(repoUrl) {
currentDir.push(newEntry);
return fetchDir(`${file.path}`, newEntry.children);
}
return Promise.resolve();
})
);
});

View File

@ -2,11 +2,12 @@ self.addEventListener('fetch', function(event) {
// console.log("fetch event", event.request.url);
if (event.request.url.indexOf('/user/') !== -1) {
event.respondWith(
caches.match(event.request).then(function(response) {
caches.match(event.request).then(response => {
// console.log("responding with ", response);
if (response !== undefined) {
return response;
}
return '';
})
);
}
@ -21,20 +22,23 @@ function getContentType(url) {
if (url.match(/\.js$/)) {
return 'application/javascript; charset=UTF-8';
}
return 'text/html; charset=UTF-8';
}
self.addEventListener('message', function(e) {
// console.log("message aya sw main", e.data);
caches.open('v1').then(function(cache) {
for (url in e.data) {
// console.log('Received data', url, e.data[url])
cache.put(
url,
new Response(e.data[url], {
headers: {
'Content-Type': getContentType(url)
}
})
);
caches.open('webmaker-files').then(function(cache) {
for (const url in e.data) {
if (Object.prototype.hasOwnProperty.call(e.data, url)) {
// console.log('Received data', url, e.data[url])
cache.put(
url,
new Response(e.data[url], {
headers: {
'Content-Type': getContentType(url)
}
})
);
}
}
});
});