Created
July 19, 2015 09:20
-
-
Save Woody88/484dcda7ac7aec1afab1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Retrieve all posts on dashboard load | |
ajax1 = | |
$.ajax | |
async: true | |
type: 'GET' | |
url: '/posts.json' | |
success: (data) -> | |
$.when(ajax1, ractive).done (a1) -> | |
posts = a1[0] | |
i = 0 | |
while i < posts.length | |
ractive.push('list', posts[i]) | |
i++ | |
## New Post ## | |
$('#new_post').on 'click', (e) -> | |
e.preventDefault() | |
send($('#message').val()) | |
$('#message').val('') | |
dispatcher = new WebSocketRails($('#posting').data('uri'), true) | |
dispatcher.on_open = (data) -> | |
console.log('Connection has been established: ', data); | |
channel = dispatcher.subscribe 'posts' | |
### Due to format_post call in the controller this function is not called anymore, not sure why..### | |
channel.bind 'new_post', (message) -> | |
console.log("inside!") | |
ractive.unshift('list', message) | |
send = (message) -> | |
dispatcher.trigger 'posting', message | |
ractive = new Ractive | |
el: '.all_posts' | |
template: '#template' | |
data: {list:[]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment