0

Starting to use Vue + Rethink, love the concepts of both of them and am starting to create a simple todo list. I've got a skeleton app done with Vue + Express + RethinkDB working properly with CRD (no update yet) operations. Everything is dandy, but of course the data is not real time. When I insert a task/todo item, I need to refresh the page to see it appear,etc.

I've looked into RethinkDB's change feeds, which looks interesting, but I'm not 100% sure how to implement them into my current Express API setup. I found a few examples playing around with Socket.io and now I am trying to implement that into my setup as well (is this necessary??).

My codebase is all up here : https://github.com/patrickbolle/vue-todo

Here's an example of my TaskList.vue component where I will display all the items -

import TaskNew from './TaskNew'
var socket = io.connect('http://localhost:8099');

export default {
  components: {
    TaskNew
  },

  data () {
    return {
      tasks: []
    }
  },

  created () {
    this.$http.get('http://localhost:8090/api/tasks').then(response => {
      this.tasks = response.data
    })
    var vm = this
    socket.on('tasksSocket', function (task) {
      vm.tasks.push(task)
    })
  },

This sort of works, when I create a new task by posting to my API, a (blank) task appears, but none of my pre-existing tasks are shown.

Here is my GET route for /tasks:

//GET - All Tasks
router.get('/tasks', (req, res) => {
  r.table("tasks").changes().run().then(function(cursor) {
    cursor.each(function(err, task) {
      io.sockets.emit("tasksSocket", task);
    })
  })
})

Honestly I'm just confusing myself more and more, I come from a Meteor background so doing this web socket/API stuff is confusing for me. If anyone could just give me a pointer in the right direction I would be very grateful.

Essentially I need to : - Retrieve tasks from my GET /api/tasks route - Grab NEW tasks from the socket... which is also on the GET /api/tasks route? - Display them in Vue JS

Pat
  • 225
  • 3
  • 11
  • How is the stand on this? I'm just starting out with `vue.js` myself and trying to work with `socket.io`. – MMachinegun Jul 25 '16 at 14:42
  • Hey @bolle, it seems like you're crossing the streams a bit when it comes to websockets and your standard HTTP request endpoints. With HTTP, you make a request and you get a response. With websockets or socketio, you kind of just have a socket that stays open and you push data through it. Definitely read this => http://socket.io/docs/. Using RethinkDB changefeeds with a socket.io connection is great because when your server gets new changefeed data you can just push it through the connection to the client. Also I'm biased (I work at RethinkDB), but you should also check out Horizon.io! – dalanmiller Jul 26 '16 at 22:18
  • 1
    @dalanmiller Hey! Thanks for the response. I ended up figuring out most of this stuff with the help of the Vue gitter chat. I've got my wip todo list up right here : https://github.com/patrickbolle/vue-todo (Just working on getting Update working properly). I'm actually looking into Horizon right now, looks really great coming from a Meteor background. – Pat Jul 28 '16 at 20:52
  • @bolle Perhaps you could paste an answer to your own question so we can all see? – geoidesic Jan 22 '18 at 10:50

0 Answers0