Skip to content

Commit ac8ac11

Browse files
authored
Merge pull request #1 from PhantasWeng/develop
Add function and add error warning
2 parents e6db9f4 + b39c5c8 commit ac8ac11

File tree

8 files changed

+426
-10
lines changed

8 files changed

+426
-10
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function (exports, LaravelEcho) {
1+
var vueEcho = (function (exports, LaravelEcho) {
22
'use strict';
33

44
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -7,6 +7,11 @@
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 @@
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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@phantasweng/vue-echo",
3-
"version": "0.1.0",
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": {
@@ -10,14 +10,17 @@
1010
"author": "PhantasWeng",
1111
"license": "ISC",
1212
"dependencies": {
13+
"laravel-echo": "^1.10.0",
14+
"pusher-js": "^7.0.3"
15+
},
16+
"devDependencies": {
17+
"@babel/core": "^7.14.2",
1318
"@rollup/plugin-babel": "^5.3.0",
19+
"@rollup/plugin-node-resolve": "^13.0.0",
1420
"@vue/compiler-sfc": "^3.0.11",
15-
"laravel-echo": "^1.10.0",
16-
"pusher-js": "^7.0.3",
1721
"rollup": "^2.47.0",
1822
"rollup-plugin-vue": "^6.0.0"
1923
},
20-
"devDependencies": {},
2124
"repository": {
2225
"type": "git",
2326
"url": "git+https://github.com/PhantasWeng/vue-echo.git"

rollup.config.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,45 @@ export default [
1111
plugins: [
1212
vue({ css: false }),
1313
babel({ babelHelpers: 'bundled' })
14+
],
15+
external: [
16+
'laravel-echo'
1417
]
1518
},
1619
// SSR build.
1720
{
1821
input: './src/index.js',
1922
output: {
2023
format: 'cjs',
21-
file: 'dist/index.ssr.js'
24+
file: 'dist/index.ssr.js',
25+
exports: 'named'
2226
},
2327
plugins: [
2428
vue({ css: false, optimizeSSR: true }),
2529
babel({ babelHelpers: 'bundled' })
30+
],
31+
external: [
32+
'laravel-echo'
2633
]
2734
},
2835
// Browser build.
2936
{
3037
input: './src/index.js',
3138
output: {
39+
name: 'vueEcho',
40+
globals: {
41+
'laravel-echo': 'LaravelEcho'
42+
},
3243
format: 'iife',
33-
file: 'dist/index.js'
44+
file: 'dist/index.js',
45+
exports: 'named'
3446
},
3547
plugins: [
3648
vue({ css: false, optimizeSSR: true }),
3749
babel({ babelHelpers: 'bundled' })
50+
],
51+
external: [
52+
'laravel-echo'
3853
]
3954
}
4055
]

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)