├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── _helpers │ ├── index.js │ └── router.js ├── _services │ ├── index.js │ └── message.service.js ├── app │ └── App.vue ├── home │ └── HomePage.vue ├── index.html └── index.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env", 4 | "stage-0" 5 | ] 6 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | typings 33 | 34 | # Optional npm cache directory 35 | .npm 36 | 37 | # Optional REPL history 38 | .node_repl_history -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jason Watmore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-rxjs-communicating-between-components 2 | 3 | Vue.js + RxJS - Communicating Between Components with Observable & Subject 4 | 5 | To see a demo and further details go to http://jasonwatmore.com/post/2019/04/02/vuejs-rxjs-communicating-between-components-with-observable-subject -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-rxjs-communicating-between-components", 3 | "version": "1.0.0", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/cornflourblue/vue-rxjs-communicating-between-components.git" 7 | }, 8 | "license": "MIT", 9 | "scripts": { 10 | "start": "webpack-dev-server --open" 11 | }, 12 | "dependencies": { 13 | "rxjs": "^6.4.0", 14 | "vue": "^2.6.8", 15 | "vue-router": "^3.0.2" 16 | }, 17 | "devDependencies": { 18 | "babel-core": "^6.26.0", 19 | "babel-loader": "^7.1.5", 20 | "babel-preset-env": "^1.6.1", 21 | "babel-preset-stage-0": "^6.24.1", 22 | "babel-preset-vue": "^2.0.2", 23 | "css-loader": "^2.1.1", 24 | "html-webpack-plugin": "^3.2.0", 25 | "path": "^0.12.7", 26 | "vue-loader": "^15.7.0", 27 | "vue-template-compiler": "^2.6.8", 28 | "webpack": "^4.29.6", 29 | "webpack-cli": "^3.2.3", 30 | "webpack-dev-server": "^3.2.1" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/_helpers/index.js: -------------------------------------------------------------------------------- 1 | export * from './router' -------------------------------------------------------------------------------- /src/_helpers/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Router from 'vue-router'; 3 | 4 | import HomePage from '@/home/HomePage'; 5 | 6 | Vue.use(Router); 7 | 8 | export const router = new Router({ 9 | mode: 'history', 10 | routes: [ 11 | { path: '/', component: HomePage }, 12 | 13 | // otherwise redirect to home 14 | { path: '*', redirect: '/' } 15 | ] 16 | }); 17 | -------------------------------------------------------------------------------- /src/_services/index.js: -------------------------------------------------------------------------------- 1 | export * from './message.service'; 2 | -------------------------------------------------------------------------------- /src/_services/message.service.js: -------------------------------------------------------------------------------- 1 | import { Subject } from 'rxjs'; 2 | 3 | const subject = new Subject(); 4 | 5 | export const messageService = { 6 | sendMessage: message => subject.next({ text: message }), 7 | clearMessages: () => subject.next(), 8 | getMessage: () => subject.asObservable() 9 | }; 10 | -------------------------------------------------------------------------------- /src/app/App.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | -------------------------------------------------------------------------------- /src/home/HomePage.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Vue.js + RxJS - Communicating Between Components with Observable & Subject 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 |

14 | Vue.js + RxJS - Communicating Between Components with Observable & Subject 15 |

16 |

17 | JasonWatmore.com 18 |

19 |
20 | 21 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | 3 | import { router } from './_helpers'; 4 | import App from './app/App'; 5 | 6 | new Vue({ 7 | el: '#app', 8 | router, 9 | render: h => h(App) 10 | }); -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 | const VueLoaderPlugin = require('vue-loader/lib/plugin') 4 | 5 | module.exports = { 6 | mode: 'development', 7 | resolve: { 8 | extensions: ['.js', '.vue'] 9 | }, 10 | module: { 11 | rules: [ 12 | { 13 | test: /\.vue?$/, 14 | loader: 'vue-loader' 15 | }, 16 | { 17 | test: /\.js?$/, 18 | loader: 'babel-loader' 19 | } 20 | ] 21 | }, 22 | resolve: { 23 | extensions: ['.js', '.vue'], 24 | alias: { 25 | '@': path.resolve(__dirname, 'src/'), 26 | } 27 | }, 28 | plugins: [ 29 | new VueLoaderPlugin(), 30 | new HtmlWebpackPlugin({ template: './src/index.html' }) 31 | ], 32 | devServer: { 33 | historyApiFallback: true 34 | } 35 | } --------------------------------------------------------------------------------