diff --git a/src/app.css b/src/app.css
deleted file mode 100644
index 527a58f..0000000
--- a/src/app.css
+++ /dev/null
@@ -1,20 +0,0 @@
-.toggle-graph {
- float: left;
- margin-left: 16px;
- cursor: pointer;
- position: relative;
- z-index: 1;
-}
-.toggle-graph svg {
- height: 20px;
- width: 20px;
-}
-.toggle-graph svg path {
- fill: #777;
-}
-
-.toggle-graph.active svg path,
-.toggle-graph:hover svg path,
-.toggle-graph:focus svg path {
- fill: black;
-}
diff --git a/src/app.js b/src/app.js
index 51a0571..bea3f58 100644
--- a/src/app.js
+++ b/src/app.js
@@ -7,23 +7,21 @@ var Model = require('./model')
var Store = require('./store')
var Template = require('./template')
-import {$on} from './helpers'
-import {updateTodo} from './todo'
-import toggleGraph from './graph'
-
-export function onLoad() { // eslint-disable-line import/prefer-default-export
- updateTodo()
- const toggleGraphButton = document.querySelector('.toggle-graph')
- $on(
- toggleGraphButton,
- 'click',
- () => {
- const active = toggleGraph()
- if (active) {
- toggleGraphButton.classList.add('active')
- } else {
- toggleGraphButton.classList.remove('active')
- }
- },
- )
+/**
+* Sets up a brand new Todo list.
+*
+* @param {string} name The name of your new to do list.
+*/
+function Todo(name) {
+ this.storage = new Store(name)
+ this.model = new Model(this.storage)
+ this.template = new Template()
+ this.view = new View(this.template)
+ this.controller = new Controller(this.model, this.view)
+}
+
+module.exports.onLoad = function onLoad() {
+ var todo = new Todo('todos-vanillajs')
+ todo.controller.setView(document.location.hash)
+ helpers.log('view set')
}
diff --git a/src/controller.js b/src/controller.js
index 8a48c90..532c5f6 100644
--- a/src/controller.js
+++ b/src/controller.js
@@ -1,4 +1,4 @@
-export default Controller
+module.exports = Controller
/**
* Takes a model and view and acts as the controller between them
@@ -110,7 +110,7 @@ Controller.prototype.addItem = function(title) {
Controller.prototype.editItem = function(id) {
var that = this
that.model.read(id, function(data) {
- that.view.render('editItem', {id, title: data[0].title})
+ that.view.render('editItem', {id: id, title: data[0].title})
})
}
@@ -120,8 +120,8 @@ Controller.prototype.editItem = function(id) {
Controller.prototype.editItemSave = function(id, title) {
var that = this
if (title.trim()) {
- that.model.update(id, {title}, function() {
- that.view.render('editItemDone', {id, title})
+ that.model.update(id, {title: title}, function() {
+ that.view.render('editItemDone', {id: id, title: title})
})
} else {
that.removeItem(id)
@@ -134,7 +134,7 @@ Controller.prototype.editItemSave = function(id, title) {
Controller.prototype.editItemCancel = function(id) {
var that = this
that.model.read(id, function(data) {
- that.view.render('editItemDone', {id, title: data[0].title})
+ that.view.render('editItemDone', {id: id, title: data[0].title})
})
}
@@ -179,10 +179,10 @@ Controller.prototype.removeCompletedItems = function() {
*/
Controller.prototype.toggleComplete = function(id, completed, silent) {
var that = this
- that.model.update(id, {completed}, function() {
+ that.model.update(id, {completed: completed}, function() {
that.view.render('elementComplete', {
- id,
- completed,
+ id: id,
+ completed: completed
})
})
@@ -230,7 +230,6 @@ Controller.prototype._updateCount = function() {
*/
Controller.prototype._filter = function(force) {
var activeRoute = this._activeRoute.charAt(0).toUpperCase() + this._activeRoute.substr(1)
-
// Update the elements on the page, which change with each completed todo
this._updateCount()
@@ -250,7 +249,6 @@ Controller.prototype._filter = function(force) {
Controller.prototype._updateFilterState = function(currentPage) {
// Store a reference to the active route, allowing us to re-filter todo
// items as they are marked complete or incomplete.
- currentPage = currentPage.split('?')[0]
this._activeRoute = currentPage
if (currentPage === '') {
diff --git a/src/graph/index.js b/src/graph/index.js
deleted file mode 100644
index 7957117..0000000
--- a/src/graph/index.js
+++ /dev/null
@@ -1,53 +0,0 @@
-import {subscribe, getTodo} from '../todo'
-
-let graphArea
-const unsubscribe = {
- store: null,
- todo: null,
-}
-
-export default toggleGraph
-
-function toggleGraph() {
- if (graphArea) {
- graphArea.remove()
- graphArea = null
- unsubscribe.store()
- unsubscribe.todo()
- return false
- } else {
- graphArea = document.createElement('div')
- document.body.querySelector('.graph-area-container').appendChild(graphArea)
- const {storage} = getTodo()
- loadAndRenderGraph(graphArea, storage)
- updateTodoSubscription()
- updateStoreSubscription(storage)
- return true
- }
-}
-
-function updateTodoSubscription() {
- if (unsubscribe.todo) {
- unsubscribe.todo()
- }
- unsubscribe.todo = subscribe(function onTodoUpdate() {
- const {storage} = getTodo()
- updateStoreSubscription(storage)
- loadAndRenderGraph(graphArea, storage)
- })
-}
-
-function updateStoreSubscription(store) {
- if (unsubscribe.store) {
- unsubscribe.store()
- }
- unsubscribe.store = store.subscribe(function onStoreUpdate() {
- loadAndRenderGraph(graphArea, store)
- })
-}
-
-function loadAndRenderGraph(node, store) {
- System.import('./render').then(({default: renderGraph}) => {
- renderGraph(node, store)
- })
-}
diff --git a/src/graph/render.js b/src/graph/render.js
deleted file mode 100644
index 5ff1555..0000000
--- a/src/graph/render.js
+++ /dev/null
@@ -1,44 +0,0 @@
-import React from 'react'
-import ReactDOM from 'react-dom'
-import {PieChart} from 'rd3'
-import {chain} from 'lodash'
-
-export default updateGraph
-
-function updateGraph(node, store) {
- store.findAll(todos => {
- ReactDOM.render(
-