Skip to content

Commit e511dd1

Browse files
committed
change m.request return value from stream to promise
remove m.prop add m.Promise update tests and examples
1 parent 54d6fd6 commit e511dd1

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

threaditjs/app.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
T.time("Setup");
22

33
var m = require("../../mithril")
4-
var request = m.request
54

65
//API calls
76
var api = {
8-
home : function() {
7+
home: function() {
98
T.timeEnd("Setup")
10-
return request({method: "GET", url: T.apiUrl + "/threads/"})
9+
return m.request({method: "GET", url: T.apiUrl + "/threads/"})
1110
},
12-
thread : function(id) {
11+
thread: function(id) {
1312
T.timeEnd("Setup")
14-
return request({method: "GET", url: T.apiUrl + "/comments/" + id}).run(T.transformResponse)
13+
return m.request({method: "GET", url: T.apiUrl + "/comments/" + id}).then(T.transformResponse)
1514
},
16-
newThread : function(text) {
17-
return request({method: "POST", url: T.apiUrl + "/threads/create",data: {text: text}})
15+
newThread: function(text) {
16+
return m.request({method: "POST", url: T.apiUrl + "/threads/create",data: {text: text}})
1817
},
19-
newComment : function(text, id) {
20-
return request({method: "POST", url: T.apiUrl + "/comments/create", data: {text: text, parent: id}});
18+
newComment: function(text, id) {
19+
return m.request({method: "POST", url: T.apiUrl + "/comments/create", data: {text: text, parent: id}});
2120
}
2221
};
2322

2423
var threads = [], current = null, loaded = false, error = false, notFound = false
2524
function loadThreads() {
2625
loaded = false
27-
api.home().run(function(response) {
26+
api.home().then(function(response) {
2827
document.title = "ThreaditJS: Mithril | Home"
2928
threads = response.data
3029
loaded = true
@@ -36,7 +35,7 @@ function loadThreads() {
3635
function loadThread(id) {
3736
loaded = false
3837
notFound = false
39-
api.thread(id).run(function(response) {
38+
api.thread(id).then(function(response) {
4039
document.title = "ThreaditJS: Mithril | " + T.trimTitle(response.root.text);
4140
loaded = true
4241
current = response
@@ -52,7 +51,7 @@ function unloadThread() {
5251

5352
function createThread() {
5453
var threadText = document.getElementById("threadText")
55-
api.newThread(threadText.value).run(function(response) {
54+
api.newThread(threadText.value).then(function(response) {
5655
threadText.value = "";
5756
threads.push(response.data);
5857
})
@@ -66,7 +65,7 @@ function showReplying(vnode) {
6665
}
6766

6867
function submitComment(vnode) {
69-
api.newComment(vnode.state.newComment, vnode.attrs.node.id).run(function(response) {
68+
api.newComment(vnode.state.newComment, vnode.attrs.node.id).then(function(response) {
7069
vnode.state.newComment = ""
7170
vnode.state.replying = false
7271
vnode.attrs.node.children.push(response.data)

0 commit comments

Comments
 (0)