-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
688fdf6
commit b914ad3
Showing
15 changed files
with
2,211 additions
and
859 deletions.
There are no files selected for viewing
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
__tests__/ |
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
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'] | ||
} | ||
} |
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
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) | ||
}) |
This file was deleted.
Oops, something went wrong.
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
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; |
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
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; |
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
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; | ||
|
||
}))); |
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
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}); |
Oops, something went wrong.