diff --git a/examples/editor-bundle/index.html b/examples/editor-bundle/index.html deleted file mode 100644 index 2fee9688..00000000 --- a/examples/editor-bundle/index.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - Markdown Editor - - - -
- - - - - - diff --git a/examples/editor/index.html b/examples/editor/index.html index 2632b0a4..4eab6a94 100644 --- a/examples/editor/index.html +++ b/examples/editor/index.html @@ -13,31 +13,20 @@ h1,h2,h3,h4,h5,h6,p {margin:0 0 10px;}
- - - - - + diff --git a/examples/threaditjs-bundle/app.js b/examples/threaditjs-bundle/app.js deleted file mode 100644 index 4774d2cf..00000000 --- a/examples/threaditjs-bundle/app.js +++ /dev/null @@ -1,177 +0,0 @@ -T.time("Setup"); - -var m = require("../../mithril") -var request = m.request - -//API calls -var api = { - home : function() { - T.timeEnd("Setup") - return request({method: "GET", url: T.apiUrl + "/threads/"}) - }, - thread : function(id) { - T.timeEnd("Setup") - return request({method: "GET", url: T.apiUrl + "/comments/" + id}).map(T.transformResponse) - }, - newThread : function(text) { - return request({method: "POST", url: T.apiUrl + "/threads/create",data: {text: text}}) - }, - newComment : function(text, id) { - return request({method: "POST", url: T.apiUrl + "/comments/create", data: {text: text, parent: id}}); - } -}; - -var threads = [], current = null, loaded = false, error = false, notFound = false -function loadThreads() { - loaded = false - api.home().map(function(response) { - document.title = "ThreaditJS: Mithril | Home" - threads = response.data - loaded = true - }, function() { - loaded = error = true - }) -} - -function loadThread(id) { - loaded = false - notFound = false - api.thread(id).map(function(response) { - document.title = "ThreaditJS: Mithril | " + T.trimTitle(response.root.text); - loaded = true - current = response - }, function(response) { - loaded = true - if (response.status === 404) notFound = true - else error = true - }) -} -function unloadThread() { - current = null -} - -function createThread() { - var threadText = document.getElementById("threadText") - api.newThread(threadText.value).map(function(response) { - threadText.value = ""; - threads.push(response.data); - }) - return false -} - -function showReplying(vnode) { - vnode.state.replying = true - vnode.state.newComment = "" - return false -} - -function submitComment(vnode) { - api.newComment(vnode.state.newComment, vnode.attrs.node.id).map(function(response) { - vnode.state.newComment = "" - vnode.state.replying = false - vnode.attrs.node.children.push(response.data) - }) - return false -} - -//shared -var Header = { - view: function() { - return [ - m("p.head_links", [ - m("a[href='https://github.com/koglerjs/threaditjs/tree/master/examples/mithril']", "Source"), - " | ", - m("a[href='http://threaditjs.com']", "ThreaditJS Home"), - ]), - m("h2", [ - m("a[href='/']", {oncreate: m.route.link}, "ThreaditJS: Mithril"), - ]), - ] - } -} - -//home -var Home = { - oninit: loadThreads, - view: function() { - return [ - m(Header), - m(".main", [ - loaded === false ? m("h2", "Loading") : - error ? m("h2", "Error! Try refreshing.") : - notFound ? m("h2", "Not found! Don't try refreshing!") : [ - threads.map(function(thread) { - return [ - m("p", [ - m("a", {href: "/thread/" + thread.id, oncreate: m.route.link}, m.trust(T.trimTitle(thread.text))), - ]), - m("p.comment_count", thread.comment_count + " comment(s)"), - m("hr"), - ] - }), - m(NewThread), - ] - ]) - ] - } -} -var NewThread = { - view: function() { - return m("form", {onsubmit: createThread}, [ - m("textarea#threadText"), - m("input", {type:"submit", value: "Post!"}), - ]) - } -} - -//thread -var Thread = { - oninit: function(vnode) { - loadThread(vnode.attrs.id) - }, - onremove: unloadThread, - view: function() { - if (current) T.time("Thread render") - return [ - m(Header), - current ? m(".main", {oncreate: function() {T.timeEnd("Thread render")}}, [ - m(ThreadNode, {node: current.root}) - ]) : null - ] - } -} -var ThreadNode = { - view: function(vnode) { - return m(".comment", [ - m("p", m.trust(vnode.attrs.node.text)), - m(".reply", m(Reply, vnode.attrs)), - m(".children", [ - vnode.attrs.node.children.map(function(child) { - return m(ThreadNode, {node: child}) - }) - ]) - ]) - } -} -var Reply = { - view: function(vnode) { - return vnode.state.replying - ? m("form", {onsubmit: function() {return submitComment(vnode)}}, [ - m("textarea", { - value: vnode.state.newComment, - oninput: function(e) { - vnode.state.newComment = e.target.value - }, - }), - m("input", {type:"submit", value: "Reply!"}), - m(".preview", m.trust(T.previewComment(vnode.state.newComment))), - ]) - : m("a", {onclick: function() {return showReplying(vnode)}}, "Reply!") - } -} - -//router -m.route(document.getElementById("app"), "/", { - "/thread/:id" : Thread, - "/" : Home, -}) diff --git a/examples/threaditjs-bundle/colors.css b/examples/threaditjs-bundle/colors.css deleted file mode 100644 index c3dc0ffb..00000000 --- a/examples/threaditjs-bundle/colors.css +++ /dev/null @@ -1,6 +0,0 @@ -html {background-color:#f5f5f5;} - -a {color:#161;text-decoration:none;} -a:hover {text-decoration:underline;} - -input[type=submit] {background-color:#5A5;color:#fff;border:0;font-weight:bold;} diff --git a/examples/threaditjs-bundle/index.html b/examples/threaditjs-bundle/index.html deleted file mode 100644 index a760d400..00000000 --- a/examples/threaditjs-bundle/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Mithril • ThreadIt.js - - - - - -
- - - - - - diff --git a/examples/threaditjs/app.js b/examples/threaditjs/app.js index 12063cab..9f763d58 100644 --- a/examples/threaditjs/app.js +++ b/examples/threaditjs/app.js @@ -1,14 +1,7 @@ T.time("Setup"); -var Stream = require("../../util/stream") -var requestService = require("../../request/request")(window) -var request = requestService.xhr -var m = require("../../render/hyperscript") -var trust = require("../../render/trust") -var renderer = require("../../render/render")(window) -var router = require("../../router/router")(window) - -requestService.setCompletionCallback(run) +var m = require("../../mithril") +var request = m.request //API calls var api = { @@ -18,7 +11,7 @@ var api = { }, thread : function(id) { T.timeEnd("Setup") - return request({method: "GET", url: T.apiUrl + "/comments/" + id}).map(T.transformResponse) + return request({method: "GET", url: T.apiUrl + "/comments/" + id}).run(T.transformResponse) }, newThread : function(text) { return request({method: "POST", url: T.apiUrl + "/threads/create",data: {text: text}}) @@ -31,11 +24,11 @@ var api = { var threads = [], current = null, loaded = false, error = false, notFound = false function loadThreads() { loaded = false - api.home().map(function(response) { + api.home().run(function(response) { document.title = "ThreaditJS: Mithril | Home" threads = response.data loaded = true - }).catch(function() { + }, function() { loaded = error = true }) } @@ -43,11 +36,11 @@ function loadThreads() { function loadThread(id) { loaded = false notFound = false - api.thread(id).map(function(response) { + api.thread(id).run(function(response) { document.title = "ThreaditJS: Mithril | " + T.trimTitle(response.root.text); loaded = true current = response - }).catch(function(response) { + }, function(response) { loaded = true if (response.status === 404) notFound = true else error = true @@ -59,7 +52,7 @@ function unloadThread() { function createThread() { var threadText = document.getElementById("threadText") - api.newThread(threadText.value).map(function(response) { + api.newThread(threadText.value).run(function(response) { threadText.value = ""; threads.push(response.data); }) @@ -73,7 +66,7 @@ function showReplying(vnode) { } function submitComment(vnode) { - api.newComment(vnode.state.newComment, vnode.attrs.node.id).map(function(response) { + api.newComment(vnode.state.newComment, vnode.attrs.node.id).run(function(response) { vnode.state.newComment = "" vnode.state.replying = false vnode.attrs.node.children.push(response.data) @@ -91,7 +84,7 @@ var Header = { m("a[href='http://threaditjs.com']", "ThreaditJS Home"), ]), m("h2", [ - m("a[href='#/']", "ThreaditJS: Mithril"), + m("a[href='/']", {oncreate: m.route.link}, "ThreaditJS: Mithril"), ]), ] } @@ -110,7 +103,7 @@ var Home = { threads.map(function(thread) { return [ m("p", [ - m("a", {href: "#/thread/" + thread.id}, trust(T.trimTitle(thread.text))), + m("a", {href: "/thread/" + thread.id, oncreate: m.route.link}, m.trust(T.trimTitle(thread.text))), ]), m("p.comment_count", thread.comment_count + " comment(s)"), m("hr"), @@ -150,7 +143,7 @@ var Thread = { var ThreadNode = { view: function(vnode) { return m(".comment", [ - m("p", trust(vnode.attrs.node.text)), + m("p", m.trust(vnode.attrs.node.text)), m(".reply", m(Reply, vnode.attrs)), m(".children", [ vnode.attrs.node.children.map(function(child) { @@ -171,25 +164,14 @@ var Reply = { }, }), m("input", {type:"submit", value: "Reply!"}), - m(".preview", trust(T.previewComment(vnode.state.newComment))), + m(".preview", m.trust(T.previewComment(vnode.state.newComment))), ]) : m("a", {onclick: function() {return showReplying(vnode)}}, "Reply!") } } //router -renderer.setEventCallback(run) -function run() { - replayRoute() -} - -var root = document.getElementById("app") -router.setPrefix("#") -var replayRoute = router.defineRoutes({ +m.route(document.getElementById("app"), "/", { "/thread/:id" : Thread, - "/" : Home -}, function(view, args) { - renderer.render(root, [m(view, args)]) -}, function() { - router.setPath("/") + "/" : Home, }) diff --git a/examples/threaditjs/index.html b/examples/threaditjs/index.html index c2f59676..a760d400 100644 --- a/examples/threaditjs/index.html +++ b/examples/threaditjs/index.html @@ -11,15 +11,7 @@
- - - - - - - - - +