Skip to content

Commit b39c5c8

Browse files
committed
Add getChannel and error warning
1 parent ca10cf7 commit b39c5c8

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

dist/index.esm.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import LaravelEcho from 'laravel-echo';
22

33
function getChannel(channels, channelName) {
44
const target = Object.keys(channels).find(channel => channels[channel].name.replace('private-', '') === channelName);
5+
6+
if (!target) {
7+
throw new Error(`[Echo] Channel name not exist: ${channelName}`);
8+
}
9+
510
return channels[target];
611
}
712

@@ -74,6 +79,7 @@ const Plugin = {
7479
subscribe: subscribe.bind(laravelEcho),
7580
unsubscribe: unsubscribe.bind(laravelEcho),
7681
getChannels: getChannels.bind(laravelEcho),
82+
getChannel: getChannel.bind(laravelEcho),
7783
getEvents: getEvents.bind(laravelEcho)
7884
});
7985
Vue.mixin({

dist/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ var vueEcho = (function (exports, LaravelEcho) {
77

88
function getChannel(channels, channelName) {
99
const target = Object.keys(channels).find(channel => channels[channel].name.replace('private-', '') === channelName);
10+
11+
if (!target) {
12+
throw new Error(`[Echo] Channel name not exist: ${channelName}`);
13+
}
14+
1015
return channels[target];
1116
}
1217

@@ -79,6 +84,7 @@ var vueEcho = (function (exports, LaravelEcho) {
7984
subscribe: subscribe.bind(laravelEcho),
8085
unsubscribe: unsubscribe.bind(laravelEcho),
8186
getChannels: getChannels.bind(laravelEcho),
87+
getChannel: getChannel.bind(laravelEcho),
8288
getEvents: getEvents.bind(laravelEcho)
8389
});
8490
Vue.mixin({

dist/index.ssr.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ var LaravelEcho__default = /*#__PURE__*/_interopDefaultLegacy(LaravelEcho);
1010

1111
function getChannel(channels, channelName) {
1212
const target = Object.keys(channels).find(channel => channels[channel].name.replace('private-', '') === channelName);
13+
14+
if (!target) {
15+
throw new Error(`[Echo] Channel name not exist: ${channelName}`);
16+
}
17+
1318
return channels[target];
1419
}
1520

@@ -82,6 +87,7 @@ const Plugin = {
8287
subscribe: subscribe.bind(laravelEcho),
8388
unsubscribe: unsubscribe.bind(laravelEcho),
8489
getChannels: getChannels.bind(laravelEcho),
90+
getChannel: getChannel.bind(laravelEcho),
8591
getEvents: getEvents.bind(laravelEcho)
8692
});
8793
Vue.mixin({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phantasweng/vue-echo",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"main": "dist/index.esm.js",
55
"description": "Vue Laravel Echo - Simply import Laravel Echo to Vue instance",
66
"scripts": {

src/helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export function getChannel (channels, channelName) {
22
const target = Object.keys(channels).find(channel => channels[channel].name.replace('private-', '') === channelName)
3+
if (!target) {
4+
throw new Error(`[Echo] Channel name not exist: ${channelName}`)
5+
}
36
return channels[target]
47
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import LaravelEcho from 'laravel-echo'
2+
import { getChannel } from './helper'
23
import { join, leave, subscribe, unsubscribe, getChannels, getEvents } from './methods'
34
window.Pusher = require('pusher-js')
45

@@ -28,6 +29,7 @@ const Plugin = {
2829
subscribe: subscribe.bind(laravelEcho),
2930
unsubscribe: unsubscribe.bind(laravelEcho),
3031
getChannels: getChannels.bind(laravelEcho),
32+
getChannel: getChannel.bind(laravelEcho),
3133
getEvents: getEvents.bind(laravelEcho)
3234
})
3335
Vue.mixin({

0 commit comments

Comments
 (0)