From 89638beacb6ac26939d039bafc33ed56e1403189 Mon Sep 17 00:00:00 2001 From: Raphael Beer Date: Mon, 13 Apr 2020 13:36:53 +0200 Subject: [PATCH] Refactor/Fix: editor identifier function for() + 1. Don't use keywords for names - rename AutoSave.for to AutoSave.fromPath 2. Return empty Object from AutoSave.fromPath for negative matches --- webapp/components/Editor/plugins/autoSave.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/components/Editor/plugins/autoSave.js b/webapp/components/Editor/plugins/autoSave.js index a6077f3ed..e90b4e1e3 100644 --- a/webapp/components/Editor/plugins/autoSave.js +++ b/webapp/components/Editor/plugins/autoSave.js @@ -7,14 +7,14 @@ export default class AutoSave extends Extension { super() this.route = $route - const { id = hash(Date.now().toString(), 0xb0b).toString(16), editorType } = AutoSave.for( + const { id = hash(Date.now().toString(), 0xb0b).toString(16), editorType } = AutoSave.fromPath( this.route.path, ) this.id = id this.editorType = editorType } - static for(path) { + static fromPath(path) { if (path === '/post/create') { return { editorType: 'post' } } @@ -24,7 +24,7 @@ export default class AutoSave extends Extension { return { editorType: 'comment', id: hash(commentMatch[1], 0xb0b).toString(16) } } - return null + return {} } static toHTML(content, schema) { @@ -35,7 +35,7 @@ export default class AutoSave extends Extension { } static load(path) { - const { id = localStorage.getItem('autosave:post:last'), editorType } = AutoSave.for(path) + const { id = localStorage.getItem('autosave:post:last'), editorType } = AutoSave.fromPath(path) const key = AutoSave.getStorageKey(id, editorType) return key ? localStorage[key] : null }