Commit 429dc9d1 authored by Pascal Hartig's avatar Pascal Hartig

vanilla-es6: Replace let with const where possible

parent 0d0c0b4a
...@@ -177,7 +177,7 @@ export default class Controller { ...@@ -177,7 +177,7 @@ export default class Controller {
* @param {boolean|undefined} force forces a re-painting of todo items. * @param {boolean|undefined} force forces a re-painting of todo items.
*/ */
_filter(force) { _filter(force) {
let active = this._activeRoute; const active = this._activeRoute;
const activeRoute = active.charAt(0).toUpperCase() + active.substr(1); const activeRoute = active.charAt(0).toUpperCase() + active.substr(1);
// Update the elements on the page, which change with each completed todo // Update the elements on the page, which change with each completed todo
......
...@@ -19,7 +19,7 @@ export function $on(target, type, callback, useCapture) { ...@@ -19,7 +19,7 @@ export function $on(target, type, callback, useCapture) {
// Attach a handler to event for all elements that match the selector, // Attach a handler to event for all elements that match the selector,
// now or in the future, based on a root element // now or in the future, based on a root element
export function $delegate(target, selector, type, handler) { export function $delegate(target, selector, type, handler) {
let dispatchEvent = event => { const dispatchEvent = event => {
const targetElement = event.target; const targetElement = event.target;
const potentialElements = qsa(selector, target); const potentialElements = qsa(selector, target);
const hasMatch = Array.from(potentialElements).includes(targetElement); const hasMatch = Array.from(potentialElements).includes(targetElement);
......
...@@ -17,7 +17,7 @@ export default class Model { ...@@ -17,7 +17,7 @@ export default class Model {
create(title, callback){ create(title, callback){
title = title || ''; title = title || '';
let newItem = { const newItem = {
title: title.trim(), title: title.trim(),
completed: false completed: false
}; };
...@@ -88,7 +88,7 @@ export default class Model { ...@@ -88,7 +88,7 @@ export default class Model {
* Returns a count of all todos * Returns a count of all todos
*/ */
getCount(callback){ getCount(callback){
let todos = { const todos = {
active: 0, active: 0,
completed: 0, completed: 0,
total: 0 total: 0
......
...@@ -39,7 +39,7 @@ export default class Store { ...@@ -39,7 +39,7 @@ export default class Store {
* }) * })
*/ */
find(query, callback){ find(query, callback){
let todos = JSON.parse(localStorage[this._dbName]).todos; const todos = JSON.parse(localStorage[this._dbName]).todos;
callback.call(this, todos.filter(todo => { callback.call(this, todos.filter(todo => {
for (let q in query) { for (let q in query) {
...@@ -72,7 +72,7 @@ export default class Store { ...@@ -72,7 +72,7 @@ export default class Store {
*/ */
save(updateData, callback, id){ save(updateData, callback, id){
const data = JSON.parse(localStorage[this._dbName]); const data = JSON.parse(localStorage[this._dbName]);
let todos = data.todos; const todos = data.todos;
const len = todos.length; const len = todos.length;
// If an ID was actually given, find the item and update each property // If an ID was actually given, find the item and update each property
...@@ -112,7 +112,7 @@ export default class Store { ...@@ -112,7 +112,7 @@ export default class Store {
*/ */
remove(id, callback){ remove(id, callback){
const data = JSON.parse(localStorage[this._dbName]); const data = JSON.parse(localStorage[this._dbName]);
let todos = data.todos; const todos = data.todos;
const len = todos.length; const len = todos.length;
for (let i = 0; i < todos.length; i++) { for (let i = 0; i < todos.length; i++) {
......
...@@ -10,8 +10,8 @@ const htmlEscapes = { ...@@ -10,8 +10,8 @@ const htmlEscapes = {
const reUnescapedHtml = /[&<>"'`]/g; const reUnescapedHtml = /[&<>"'`]/g;
const reHasUnescapedHtml = new RegExp(reUnescapedHtml.source); const reHasUnescapedHtml = new RegExp(reUnescapedHtml.source);
let escape = str => (str && reHasUnescapedHtml.test(str)) ? str.replace(reUnescapedHtml, escapeHtmlChar) : str; const escape = str => (str && reHasUnescapedHtml.test(str)) ? str.replace(reUnescapedHtml, escapeHtmlChar) : str;
let escapeHtmlChar = chr => htmlEscapes[chr]; const escapeHtmlChar = chr => htmlEscapes[chr];
export default class Template { export default class Template {
constructor() { constructor() {
...@@ -44,10 +44,10 @@ export default class Template { ...@@ -44,10 +44,10 @@ export default class Template {
* }) * })
*/ */
show(data){ show(data){
let view = data.map(d => { const view = data.map(d => {
let template = this.defaultTemplate; const template = this.defaultTemplate;
let completed = d.completed ? 'completed' : ''; const completed = d.completed ? 'completed' : '';
let checked = d.completed ? 'checked' : ''; const checked = d.completed ? 'checked' : '';
return this.defaultTemplate return this.defaultTemplate
.replace('{{id}}', d.id) .replace('{{id}}', d.id)
...@@ -66,7 +66,7 @@ export default class Template { ...@@ -66,7 +66,7 @@ export default class Template {
* @returns {string} String containing the count * @returns {string} String containing the count
*/ */
itemCounter(activeTodos){ itemCounter(activeTodos){
let plural = activeTodos === 1 ? '' : 's'; const plural = activeTodos === 1 ? '' : 's';
return `<strong>${activeTodos}</strong> item${plural} left`; return `<strong>${activeTodos}</strong> item${plural} left`;
} }
......
import {qs, qsa, $on, $parent, $delegate} from './helpers'; import {qs, qsa, $on, $parent, $delegate} from './helpers';
let _itemId = element => parseInt($parent(element, 'li').dataset.id, 10); const _itemId = element => parseInt($parent(element, 'li').dataset.id, 10);
let _setFilter = currentPage => { const _setFilter = currentPage => {
qs('.filters .selected').className = ''; qs('.filters .selected').className = '';
qs(`.filters [href="#/${currentPage}"]`).className = 'selected'; qs(`.filters [href="#/${currentPage}"]`).className = 'selected';
}; };
let _elementComplete = (id, completed) => { const _elementComplete = (id, completed) => {
const listItem = qs(`[data-id="${id}"]`); const listItem = qs(`[data-id="${id}"]`);
if (!listItem) { if (!listItem) {
...@@ -20,7 +20,7 @@ let _elementComplete = (id, completed) => { ...@@ -20,7 +20,7 @@ let _elementComplete = (id, completed) => {
qs('input', listItem).checked = completed; qs('input', listItem).checked = completed;
}; };
let _editItem = (id, title) => { const _editItem = (id, title) => {
const listItem = qs(`[data-id="${id}"]`); const listItem = qs(`[data-id="${id}"]`);
if (!listItem) { if (!listItem) {
...@@ -29,7 +29,7 @@ let _editItem = (id, title) => { ...@@ -29,7 +29,7 @@ let _editItem = (id, title) => {
listItem.className += ' editing'; listItem.className += ' editing';
let input = document.createElement('input'); const input = document.createElement('input');
input.className = 'edit'; input.className = 'edit';
listItem.appendChild(input); listItem.appendChild(input);
...@@ -109,7 +109,7 @@ export default class View { ...@@ -109,7 +109,7 @@ export default class View {
} }
_bindItemEditDone(handler) { _bindItemEditDone(handler) {
let self = this; const self = this;
$delegate(self.$todoList, 'li .edit', 'blur', function () { $delegate(self.$todoList, 'li .edit', 'blur', function () {
if (!this.dataset.iscanceled) { if (!this.dataset.iscanceled) {
...@@ -129,11 +129,11 @@ export default class View { ...@@ -129,11 +129,11 @@ export default class View {
} }
_bindItemEditCancel(handler) { _bindItemEditCancel(handler) {
let self = this; const self = this;
$delegate(self.$todoList, 'li .edit', 'keyup', function (event) { $delegate(self.$todoList, 'li .edit', 'keyup', function (event) {
if (event.keyCode === self.ESCAPE_KEY) { if (event.keyCode === self.ESCAPE_KEY) {
let id = _itemId(this); const id = _itemId(this);
this.dataset.iscanceled = true; this.dataset.iscanceled = true;
this.blur(); this.blur();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment