vuejs / vue-requests

Need a Vue.js module or looking for ideas?
MIT License
69 stars 6 forks source link

Vue Wamp v2 #15

Open douglasgalico opened 8 years ago

douglasgalico commented 8 years ago

Component for Wamp v2 (Web Application Messaging Protocol) that handles publish, subscribe and RPC calls (call and offer).

Maybe an AutobahnJS Wrapper?

simplesmiler commented 8 years ago

I don't think this should be a component, but rather a plugin that allows other components to interact with WAMP.

Possible API:

var VueWamp = require('...');
Vue.use(VueWamp);

new Vue({
  wamp: new VueWamp({ <wamp_options> }),
});
module.exports = {
  template: `
    <div>
      <ul>
        <li v-for="message in messages" track-by="id">{{ message.text }}</li>
      </ul>
      <form @submit="submit">
        <input v-model="message">
        <button type="submit">Send</button>
      </form>
    </div>
  `,
  data: function() {
    return {
      message: '',
      messages: [],
    };
  },
  wamp: {
    subscribe: {
      'chat-message': function(message) {
        this.messages.push({ id: cuid(), text: message });
      },
    },
    register: {
      'method.endpoint': function(paload) {
        return this.$wamp.call('method.delegate', payload);
      },
    },
  },
  methods: {
    submit: function() {
      this.$wamp.publish('chat-message', this.message);
      this.message = '';
    },
  },
};

Things to be aware of:

lajosbencz commented 7 years ago

I've put together an AutobahnJS plugin for Vue2: https://github.com/lajosbencz/vue-wamp

It's not mature in any way, so feedback is welcome! :]