Skip to content

nk-components/vue-mediator-mixin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vue-mediator-mixin Build Status

Vue.js wrapper for nk-mediator.

Install

With npm do:

$ npm install vue-mediator-mixin --save

Usage

var Vue = require('vue');
var mediatorMixin = require('vue-mediator-mixin');

var Component = Vue.extend({
  mixins: [mediatorMixin],
  ready: function() {
    this.sub('channel:type', this._onEvent);
  },

  methods: {
    _onEvent: function() {
      console.log('channel:type fired!');
    }
  }
});

module.exports = Header;

Like Vue's events, you can subscribe to mediator's events using vm options:

var Vue = require('vue');
var mediatorMixin = require('vue-mediator-mixin');

var Component = Vue.extend({
  mixins: [mediatorMixin],
  mediator: {
    'channel:type': '_onEvent',
    'foo:bar': function() {
    }
  },

  methods: {
    _onEvent: function() {
      console.log('channel:type fired!');
    }
  }
});

module.exports = Header;

API

.pub(eventName, data...)

.sub(eventName, callback)

.subOnce(eventName, callback)

.unsub(eventName, callback [optional])

.unsubAll()

License

MIT

About

Vue.js wrapper for nk-mediator

Resources

License

Stars

Watchers

Forks

Packages

No packages published