Skip to content

Commit

Permalink
Use ES modules (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangmingshan authored Jan 25, 2018
1 parent 688fdf6 commit b914ad3
Show file tree
Hide file tree
Showing 15 changed files with 2,211 additions and 859 deletions.
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2

jobs:
build:
docker:
- image: circleci/node:latest
steps:
- checkout
- run: yarn
- run: yarn run lint
- run: yarn run test -- -t $CI_CODECOV_TOKEN
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
__tests__/
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
},
env: {
browser: true
},
extends: 'standard',
rules: {
'space-before-function-paren': [2, 'never']
}
}
90 changes: 90 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const Vue = require('vue')
const VueBus = require('../dist/vue-bus.common')

Vue.use(VueBus)

test('Vue.bus', () => {
const vm = new Vue({
data() {
return { count: 0 }
},
created() {
this.$bus.on('add', num => { this.count += num })
this.$bus.once('addOnce', num => { this.count += num })
},
methods: {
clean() {
this.$bus.off('add')
}
}
})

const obj = {
fire() {
Vue.bus.emit('add', 1)
},
fireOnce() {
Vue.bus.emit('addOnce', 1)
}
}

obj.fire()
expect(vm.count).toBe(1)

obj.fire()
expect(vm.count).toBe(2)

vm.clean()
obj.fire()
expect(vm.count).toBe(2)

obj.fireOnce()
expect(vm.count).toBe(3)

obj.fireOnce()
expect(vm.count).toBe(3)
})

test('this.$bus', () => {
const vm1 = new Vue({
data() {
return { count: 0 }
},
created() {
this.$bus.on('add', num => { this.count += num })
this.$bus.once('addOnce', num => { this.count += num })
},
methods: {
clean() {
this.$bus.off('add')
}
}
})

const vm2 = new Vue({
methods: {
fire() {
this.$bus.emit('add', 1)
},
fireOnce() {
this.$bus.emit('addOnce', 1)
}
}
})

vm2.fire()
expect(vm1.count).toBe(1)

vm2.fire()
expect(vm1.count).toBe(2)

vm1.clean()
vm2.fire()
expect(vm1.count).toBe(2)

vm2.fireOnce()
expect(vm1.count).toBe(3)

vm2.fireOnce()
expect(vm1.count).toBe(3)
})
7 changes: 0 additions & 7 deletions circle.yml

This file was deleted.

47 changes: 47 additions & 0 deletions dist/vue-bus.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* vue-bus v1.1.0
* https://github.com/yangmingshan/vue-bus
* @license MIT
*/
'use strict';

function VueBus(Vue) {
var bus = new Vue();

Object.defineProperties(bus, {
on: {
get: function get() {
return this.$on
}
},
once: {
get: function get() {
return this.$once
}
},
off: {
get: function get() {
return this.$off
}
},
emit: {
get: function get() {
return this.$emit
}
}
});

Vue.bus = bus;

Object.defineProperty(Vue.prototype, '$bus', {
get: function get() {
return bus
}
});
}

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(VueBus);
}

module.exports = VueBus;
45 changes: 45 additions & 0 deletions dist/vue-bus.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* vue-bus v1.1.0
* https://github.com/yangmingshan/vue-bus
* @license MIT
*/
function VueBus(Vue) {
var bus = new Vue();

Object.defineProperties(bus, {
on: {
get: function get() {
return this.$on
}
},
once: {
get: function get() {
return this.$once
}
},
off: {
get: function get() {
return this.$off
}
},
emit: {
get: function get() {
return this.$emit
}
}
});

Vue.bus = bus;

Object.defineProperty(Vue.prototype, '$bus', {
get: function get() {
return bus
}
});
}

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(VueBus);
}

export default VueBus;
53 changes: 53 additions & 0 deletions dist/vue-bus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* vue-bus v1.1.0
* https://github.com/yangmingshan/vue-bus
* @license MIT
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.VueBus = factory());
}(this, (function () { 'use strict';

function VueBus(Vue) {
var bus = new Vue();

Object.defineProperties(bus, {
on: {
get: function get() {
return this.$on
}
},
once: {
get: function get() {
return this.$once
}
},
off: {
get: function get() {
return this.$off
}
},
emit: {
get: function get() {
return this.$emit
}
}
});

Vue.bus = bus;

Object.defineProperty(Vue.prototype, '$bus', {
get: function get() {
return bus
}
});
}

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(VueBus);
}

return VueBus;

})));
6 changes: 6 additions & 0 deletions dist/vue-bus.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* vue-bus v1.1.0
* https://github.com/yangmingshan/vue-bus
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueBus=t()}(this,function(){"use strict";function e(e){var t=new e;Object.defineProperties(t,{on:{get:function(){return this.$on}},once:{get:function(){return this.$once}},off:{get:function(){return this.$off}},emit:{get:function(){return this.$emit}}}),e.bus=t,Object.defineProperty(e.prototype,"$bus",{get:function(){return t}})}return"undefined"!=typeof window&&window.Vue&&window.Vue.use(e),e});
54 changes: 0 additions & 54 deletions index.js

This file was deleted.

Loading

0 comments on commit b914ad3

Please sign in to comment.