easy-eventbus
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.eventBus=t():e.eventBus=t()}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n=function(e,t){var r=0;this.listeners.some(function(t,n){var i=t.type===e;return i&&(r=n),i})?this.listeners[r]={type:e,func:t}:this.listeners.push({type:e,func:t})},i=function(e){this.listeners=this.listeners.filter(function(t){return t.type!==e})},s=function(){return this.listeners},u=function(){this.createSubscriber=function(){this.count+=1,this.$emit("create"),this.id+=1;var e=this.id,t={addListener:n,removeListener:i,getListener:s,listeners:[]};return Object.defineProperty(t,"id",{value:e,writable:!1}),this.subscribers.push(t),this.subscribers[this.subscribers.length-1]},this.$emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];this.subscribers.forEach(function(r){r.listeners.some(function(r){if(r.type===e)return r.func.apply(r,t),!0})})},this.dispatch=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];this.$emit.apply(this,[e].concat(t))},this.removeSubscriber=function(e){var t=this;return this.subscribers.some(function(r,n){return r.id===e&&(t.subscribers[n]=null,t.subscribers.splice(n,1),t.count-=1,!0)})},this.removeAllSubscriber=function(){this.count=0,this.subscribers=[]},this.getSubscriber=function(e){return e?this.subscribers.filter(function(t){return t.id===e})[0]:this.subscribers},this.subscribers=[],this.id=0,this.count=0};t.default=u}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.eventBus=t():e.eventBus=t()}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n=function(e,t){var r=0;this.listeners.some(function(t,n){var i=t.type===e;return i&&(r=n),i})?this.listeners[r]={type:e,func:t}:this.listeners.push({type:e,func:t})},i=function(e){this.listeners=this.listeners.filter(function(t){return t.type!==e})},s=function(e){this.listeners=[]},u=function(){return this.listeners},o=function(){this.createSubscriber=function(){this.count+=1,this.$emit("create"),this.id+=1;var e=this.id,t={addListener:n,removeListener:i,removeAllListener:s,getListener:u,listeners:[]};return Object.defineProperty(t,"id",{value:e,writable:!1}),this.subscribers.push(t),this.subscribers[this.subscribers.length-1]},this.$emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];this.subscribers.forEach(function(r){r.listeners.some(function(r){if(r.type===e)return r.func.apply(r,t),!0})})},this.dispatch=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];this.$emit.apply(this,[e].concat(t))},this.removeSubscriber=function(e){var t=this;return this.subscribers.some(function(r,n){return r.id===e&&(t.subscribers[n]=null,t.subscribers.splice(n,1),t.count-=1,!0)})},this.removeAllSubscriber=function(){this.count=0,this.subscribers=[]},this.getSubscriber=function(e){return e?this.subscribers.filter(function(t){return t.id===e})[0]:this.subscribers},this.subscribers=[],this.id=0,this.count=0};t.default=o}])}); |
@@ -1,18 +0,6 @@ | ||
import Eventbus from './src/eventBus' | ||
declare const Eventbus: { | ||
listener: eventbus.listener | ||
subscriber: eventbus.subscriber | ||
} | ||
declare namespace EasyEventbus { | ||
interface listener { | ||
type: string | ||
func: Function | ||
} | ||
interface subscriber { | ||
addListener: Function | ||
removeListener: Function | ||
removeAllListener: Function | ||
getListener: Function | ||
listeners: listener[] | ||
id?: number | ||
} | ||
} | ||
export default Eventbus |
{ | ||
"name": "easy-eventbus", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "this is a library for eventbus", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "unit": "cross-env NODE_ENV=test karma start test/karma.conf.js", |
@@ -15,3 +15,3 @@ /** | ||
let index = 0 | ||
const isSame = this.listeners.some((v: EasyEventbus.listener, i: number) => { | ||
const isSame = this.listeners.some((v: eventbus.listener, i: number) => { | ||
const isSameType = v.type === type | ||
@@ -42,3 +42,3 @@ if (isSameType) { | ||
const _removeListener = function(type: string) { | ||
this.listeners = this.listeners.filter((v: EasyEventbus.listener) => v.type !== type) | ||
this.listeners = this.listeners.filter((v: eventbus.listener) => v.type !== type) | ||
} | ||
@@ -51,3 +51,3 @@ | ||
*/ | ||
const _removeAllListener = function (type: string) { | ||
const _removeAllListener = function(type: string) { | ||
this.listeners = [] | ||
@@ -69,3 +69,3 @@ } | ||
class Observer { | ||
public subscribers: EasyEventbus.subscriber[] | ||
public subscribers: eventbus.subscriber[] | ||
public id: number | ||
@@ -98,3 +98,3 @@ public count: number | ||
const id = this.id | ||
const obj: EasyEventbus.subscriber = { | ||
const obj: eventbus.subscriber = { | ||
addListener: _addListener, | ||
@@ -122,4 +122,4 @@ removeListener: _removeListener, | ||
$emit = function(type: string, ...args: []) { | ||
this.subscribers.forEach((v: EasyEventbus.subscriber) => { | ||
v.listeners.some((v: EasyEventbus.listener) => { | ||
this.subscribers.forEach((v: eventbus.subscriber) => { | ||
v.listeners.some((v: eventbus.listener) => { | ||
if (v.type === type) { | ||
@@ -151,3 +151,3 @@ v.func(...args) | ||
removeSubscriber = function(id: number) { | ||
return this.subscribers.some((v: EasyEventbus.subscriber, i: number) => { | ||
return this.subscribers.some((v: eventbus.subscriber, i: number) => { | ||
if (v.id === id) { | ||
@@ -182,3 +182,3 @@ this.subscribers[i] = null | ||
if (id) { | ||
return this.subscribers.filter((v: EasyEventbus.subscriber) => v.id === id)[0] | ||
return this.subscribers.filter((v: eventbus.subscriber) => v.id === id)[0] | ||
} | ||
@@ -185,0 +185,0 @@ return this.subscribers |
111122
32
1529