This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const api = (() => { | |
const url = `${window.location.origin}/api` | |
const addTodo = todo => | |
axios.post(url, todo) | |
.then(res => res.data) | |
const deleteTodo = id => | |
axios.delete(`${url}/${id}`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handlers = (() => { | |
const _toast = message => { | |
Materialize.toast(message, 1500, 'rounded') | |
} | |
const _updateApi = (update, id) => { | |
api.updateTodo(update, id) | |
.then(updatedTodo => { | |
const originalTodo = store.findById(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const attachListeners = () => { | |
$('#add-todo').submit(handlers.addHandler) | |
$('.collection').on('click', '.delete', handlers.deleteHandler) | |
$('.collection').on('click', '.save', handlers.updateTextHandler) | |
$('.collection').on('submit', 'form', handlers.updateTextHandler) | |
$('.collection').on('click', '.edit', handlers.editTextHandler) | |
$('.collection').on('click', '.done', handlers.updateDoneHandler) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(() => { | |
render.dom() | |
attachListeners() | |
api.getTodos() | |
.then(todos => { | |
store.addTodosOnLoad(todos) | |
render.todos() | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset='UTF-8'> | |
<title>State Management with jQuery</title> | |
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css'> | |
<link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'> | |
<link rel='stylesheet' href='style.css'> | |
</head> | |
<body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Todo = require('./model') | |
exports.addTodo = (req, res) => { | |
Todo | |
.create(req.body) | |
.then(todo => { | |
res.json(todo) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const router = require('express').Router() | |
const controllers = require('./controller') | |
router.get('/', controllers.getTodos) | |
router.post('/', controllers.addTodo) | |
router.delete('/:id', controllers.deleteTodo) | |
router.put('/:id', controllers.updateTodo) | |
module.exports = router |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose') | |
mongoose.Promise = global.Promise | |
const TodoSchema = new mongoose.Schema({ | |
text: { | |
type: String, | |
required: 'please provide some text for your todo' | |
}, | |
done: { | |
type: String, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const express = require('express') | |
const mongoose = require('mongoose') | |
const path = require('path') | |
const app = express() | |
const todoRouter = require('./todo/router') | |
// set public folder | |
app.use(express.static('public')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div>hello</div> |