Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(todoapp): Refactor to plain ES module #344

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions source/use-case/todoapp/.babelrc

This file was deleted.

1 change: 1 addition & 0 deletions source/use-case/todoapp/.esmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cjs":true,"esm":"js"}
291 changes: 0 additions & 291 deletions source/use-case/todoapp/build.js

This file was deleted.

2 changes: 1 addition & 1 deletion source/use-case/todoapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<!-- TODO LIST -->
</div>
</div>
<script src="./build.js"></script>
<script src="./src/index.js" type="module"></script>
</body>
</html>
14 changes: 3 additions & 11 deletions source/use-case/todoapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
"test": "test"
},
"scripts": {
"build": "browserify src/index.js -o build.js",
"watch": "watchify -d src/index.js -o build.js",
"test": "mocha"
"test": "mocha test/"
},
"browserify": {
"transform": [
Expand All @@ -24,13 +22,7 @@
"es6"
],
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.9.0",
"babelify": "^7.2.0",
"browserify": "^13.0.0",
"mocha": "^2.5.3",
"watchify": "^3.7.0"
"@std/esm": "^0.20.0",
"mocha": "^2.5.3"
}
}
5 changes: 3 additions & 2 deletions source/use-case/todoapp/src/EventEmitter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// LICENSE : MIT
"use strict";

/*
Simple EventEmitter
* Simple EventEmitter
*/
export default class EventEmitter {
export class EventEmitter {
constructor() {
this._handlers = {};
}
Expand Down
11 changes: 7 additions & 4 deletions source/use-case/todoapp/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// LICENSE : MIT
"use strict";
import { TodoListModel } from "./models/TodoListModel";
import TodoListRendering from "./views/TodoListRendering";
import { TodoListModel } from "./models/TodoListModel.js";
import { TodoListRendering } from "./views/TodoListRendering.js";

// Entry Point
function onLoad() {
// add event to DOM elements
Expand Down Expand Up @@ -30,10 +31,12 @@ function onLoad() {

const unbindHandler = todoListModel.onChange(() => {
const todoItemList = todoListModel.getAllTodoList();
console.log("changed", todoItemList);
rendering.render(todoItemList, {
toggleComplete
});
});

window.addEventListener("unload", unbindHandler);
}
window.addEventListener("load", onLoad);

window.addEventListener("load", onLoad);
6 changes: 4 additions & 2 deletions source/use-case/todoapp/src/models/TodoListModel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// LICENSE : MIT
"use strict";
import EventEmitter from "./../EventEmitter";
import { EventEmitter } from "../EventEmitter.js";
// unique id
let todoIdx = 0;

export class TodoItemModel {
constructor({ title, completed = false } = {}) {
this.id = todoIdx++;
Expand All @@ -14,6 +15,7 @@ export class TodoItemModel {
return this.completed;
}
}

// model
export class TodoListModel extends EventEmitter {
constructor(todoList = []) {
Expand Down Expand Up @@ -47,4 +49,4 @@ export class TodoListModel extends EventEmitter {
// emit change
this.emit("change");
}
}
}
7 changes: 3 additions & 4 deletions source/use-case/todoapp/src/views/TodoListRendering.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// LICENSE : MIT
"use strict";
// rendering
export default class TodoListRendering {
// Rendering Todo List
export class TodoListRendering {
constructor(containerNode) {
this.containerNode = containerNode;
}
Expand Down Expand Up @@ -37,4 +36,4 @@ export default class TodoListRendering {
// render
this.containerNode.appendChild(orderListTag);
}
}
}
5 changes: 3 additions & 2 deletions source/use-case/todoapp/test/EventEmitter-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// LICENSE : MIT
"use strict";
const assert = require("assert");
import EventEmitter from "../src/EventEmitter";
import { EventEmitter } from "../src/EventEmitter.js";

describe("EventEmitter", function() {
let emitter;
beforeEach(function() {
Expand Down Expand Up @@ -40,4 +41,4 @@ describe("EventEmitter", function() {
emitter.emit(key);
});
});
});
});
2 changes: 1 addition & 1 deletion source/use-case/todoapp/test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--compilers js:babel-register
--require @std/esm