1
1
T . time ( "Setup" ) ;
2
2
3
3
var m = require ( "../../mithril" )
4
- var request = m . request
5
4
6
5
//API calls
7
6
var api = {
8
- home : function ( ) {
7
+ home : function ( ) {
9
8
T . timeEnd ( "Setup" )
10
- return request ( { method : "GET" , url : T . apiUrl + "/threads/" } )
9
+ return m . request ( { method : "GET" , url : T . apiUrl + "/threads/" } )
11
10
} ,
12
- thread : function ( id ) {
11
+ thread : function ( id ) {
13
12
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 )
15
14
} ,
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 } } )
18
17
} ,
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 } } ) ;
21
20
}
22
21
} ;
23
22
24
23
var threads = [ ] , current = null , loaded = false , error = false , notFound = false
25
24
function loadThreads ( ) {
26
25
loaded = false
27
- api . home ( ) . run ( function ( response ) {
26
+ api . home ( ) . then ( function ( response ) {
28
27
document . title = "ThreaditJS: Mithril | Home"
29
28
threads = response . data
30
29
loaded = true
@@ -36,7 +35,7 @@ function loadThreads() {
36
35
function loadThread ( id ) {
37
36
loaded = false
38
37
notFound = false
39
- api . thread ( id ) . run ( function ( response ) {
38
+ api . thread ( id ) . then ( function ( response ) {
40
39
document . title = "ThreaditJS: Mithril | " + T . trimTitle ( response . root . text ) ;
41
40
loaded = true
42
41
current = response
@@ -52,7 +51,7 @@ function unloadThread() {
52
51
53
52
function createThread ( ) {
54
53
var threadText = document . getElementById ( "threadText" )
55
- api . newThread ( threadText . value ) . run ( function ( response ) {
54
+ api . newThread ( threadText . value ) . then ( function ( response ) {
56
55
threadText . value = "" ;
57
56
threads . push ( response . data ) ;
58
57
} )
@@ -66,7 +65,7 @@ function showReplying(vnode) {
66
65
}
67
66
68
67
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 ) {
70
69
vnode . state . newComment = ""
71
70
vnode . state . replying = false
72
71
vnode . attrs . node . children . push ( response . data )
0 commit comments