summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015-babel-webpack/src/todo.js
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015-babel-webpack/src/todo.js')
-rw-r--r--third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015-babel-webpack/src/todo.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015-babel-webpack/src/todo.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015-babel-webpack/src/todo.js
new file mode 100644
index 0000000000..e51cf361aa
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015-babel-webpack/src/todo.js
@@ -0,0 +1,41 @@
+import View from './view'
+import Controller from './controller'
+import Model from './model'
+import Store from './store'
+import Template from './template'
+import {remove} from './helpers'
+
+export {updateTodo, getTodo, subscribe}
+
+let todo
+const subscribers = []
+
+/**
+ * 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)
+}
+
+function updateTodo() {
+ todo = new Todo('todos-vanillajs')
+ todo.controller.setView(document.location.hash)
+ subscribers.forEach(s => s())
+}
+
+function getTodo() {
+ return todo
+}
+
+function subscribe(cb) {
+ subscribers.push(cb)
+ return function unsubscribe() {
+ remove(subscribers, cb)
+ }
+}