Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ind.ie Projects
Set
Commits
fe68d57d
Unverified
Commit
fe68d57d
authored
May 12, 2017
by
Aral Balkan
Browse files
Migrate example with client side updates from App.net to Mastodon
parent
30878dd5
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
routes/posts-client-side-updates.coffee
View file @
fe68d57d
...
...
@@ -2,7 +2,7 @@
#
# Set client side updates example.
#
# Displays the global timeline from
App.net
with client side updates
# Displays the global timeline from
mastodon.social
with client side updates
# using the same template.
#
# Copyright © Aral Balkan.
...
...
@@ -15,36 +15,26 @@ superagent = require 'superagent'
exports
.
route
=
(
request
,
response
)
->
superagent
.
get
(
'https://
alpha-api.app.net/stream/0/posts/stream/global
'
)
superagent
.
get
(
'https://
mastodon.social/api/v1/timelines/public
'
)
.
end
(
error
,
globalTimelineResponse
)
->
globalTimeline
=
globalTimelineResponse
.
body
# Attach a custom function to the data to count the number of posts
globalTimelineResponse
.
body
.
numberOfPosts
=
->
if
this
.
data
return
this
.
data
.
length
else
return
0
# Ask for the data to be injected into the rendered template
# (we’re going to append to it via Ajax calls on the client‐side to render an
# expanding timeline of App.net posts.)
globalTimeline
.
__set
=
injectData
:
yes
# Handle network and App.net errors gracefully.
if
error
# There was a network error
globalTimeline
.
errorType
=
'Network'
globalTimeline
.
error
=
error
# There was a network error
globalTimeline
.
errorType
=
'Network'
globalTimeline
.
error
=
error
else
if
not
globalTimeline
.
data
else
if
not
globalTimeline
# There was an App.net error
globalTimeline
.
errorType
=
'App.net'
globalTimeline
.
error
=
"(#
#{
globalTimeline
.
meta
.
code
}
)
#{
globalTimeline
.
meta
.
error_message
}
"
# There was an App.net error
globalTimeline
.
errorType
=
'App.net'
globalTimeline
.
error
=
"Could not get the public timeline."
# Render the response and ask for the data to be injected into the rendered template
# (we’re going to append to it via Ajax calls on the client‐side to render an
# expanding timeline of App.net posts.)
# Render the response
response
.
render
'posts-client-side-updates'
,
globalTimeline
response
.
render
'posts-client-side-updates'
,
{
data
:
globalTimeline
,
__set
:
{
injectData
:
yes
}
}
views/posts-client-side-updates.html
View file @
fe68d57d
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment