├── .gitignore ├── README.md ├── codecon_banner.png ├── error-boundary ├── .browserslistrc ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ └── index.html └── src │ ├── App.vue │ ├── assets │ └── logo.png │ ├── components │ ├── Content.vue │ ├── ErrorBoundary.vue │ ├── Fallback.vue │ ├── Footer.vue │ ├── Header.vue │ ├── Loading.vue │ └── PostList.vue │ ├── global.js │ ├── main.js │ ├── services │ ├── index.js │ └── posts.js │ └── stores │ ├── posts.js │ └── user.js ├── factory-components ├── .browserslistrc ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ └── index.html └── src │ ├── App.vue │ ├── assets │ └── logo.png │ ├── components │ ├── Modal.vue │ ├── ModalFactory.vue │ ├── ModalLogin.vue │ └── ModalRegister.vue │ └── main.js ├── global-services ├── .browserslistrc ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ └── index.html └── src │ ├── App.vue │ ├── assets │ └── logo.png │ ├── components │ ├── Content.vue │ ├── Footer.vue │ ├── Header.vue │ └── Loading.vue │ ├── global.js │ ├── main.js │ ├── services │ ├── index.js │ └── posts.js │ └── stores │ ├── posts.js │ └── user.js ├── scoped-slots ├── .browserslistrc ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ └── index.html └── src │ ├── App.vue │ ├── assets │ └── logo.png │ ├── components │ ├── HelloWorld.vue │ ├── QueryRenderer.vue │ └── WithMouse.vue │ ├── main.js │ └── services │ ├── index.js │ └── posts.js └── vue-global-store ├── .browserslistrc ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html └── src ├── App.vue ├── assets └── logo.png ├── components ├── Content.vue ├── Footer.vue └── Header.vue ├── main.js ├── services ├── index.js └── posts.js └── stores ├── posts.js └── user.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## `codecon-vuejs-components-patterns-workshop` 2 | 3 | > Workshop para a [codecon](https://codecon.dev/workshops/patterns-componentes-vue-js) 4 | 5 | Embora os componentes sejam uma das melhores coisas que já aconteceram no front-end, a capacidade de reutilização e a escalabilidade tornam-se as coisas mais difíceis de gerenciar conforme sua base de código e equipe crescem. Aqui vou mostrar os padrões de componentes você precisa considerar para reutilização e escalabilidade do código. 6 | 7 | ![](./codecon_banner.png) 8 | 9 | 10 | -------------------------------------------------------------------------------- /codecon_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/codecon_banner.png -------------------------------------------------------------------------------- /error-boundary/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /error-boundary/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /error-boundary/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: [ 7 | 'plugin:vue/essential', 8 | '@vue/standard' 9 | ], 10 | parserOptions: { 11 | parser: 'babel-eslint' 12 | }, 13 | rules: { 14 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 15 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /error-boundary/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /error-boundary/README.md: -------------------------------------------------------------------------------- 1 | # vue-global-store 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /error-boundary/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /error-boundary/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-global-store", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.22.0", 12 | "core-js": "^3.6.5", 13 | "vue": "^2.6.11" 14 | }, 15 | "devDependencies": { 16 | "@vue/cli-plugin-babel": "~4.5.0", 17 | "@vue/cli-plugin-eslint": "~4.5.0", 18 | "@vue/cli-service": "~4.5.0", 19 | "@vue/eslint-config-standard": "^5.1.2", 20 | "babel-eslint": "^10.1.0", 21 | "eslint": "^6.7.2", 22 | "eslint-plugin-import": "^2.20.2", 23 | "eslint-plugin-node": "^11.1.0", 24 | "eslint-plugin-promise": "^4.2.1", 25 | "eslint-plugin-standard": "^4.0.0", 26 | "eslint-plugin-vue": "^6.2.2", 27 | "lint-staged": "^9.5.0", 28 | "vue-template-compiler": "^2.6.11" 29 | }, 30 | "gitHooks": { 31 | "pre-commit": "lint-staged" 32 | }, 33 | "lint-staged": { 34 | "*.{js,jsx,vue}": [ 35 | "vue-cli-service lint", 36 | "git add" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /error-boundary/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/error-boundary/public/favicon.ico -------------------------------------------------------------------------------- /error-boundary/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /error-boundary/src/App.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 48 | -------------------------------------------------------------------------------- /error-boundary/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/error-boundary/src/assets/logo.png -------------------------------------------------------------------------------- /error-boundary/src/components/Content.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 33 | -------------------------------------------------------------------------------- /error-boundary/src/components/ErrorBoundary.vue: -------------------------------------------------------------------------------- 1 | 27 | -------------------------------------------------------------------------------- /error-boundary/src/components/Fallback.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 14 | -------------------------------------------------------------------------------- /error-boundary/src/components/Footer.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 36 | -------------------------------------------------------------------------------- /error-boundary/src/components/Header.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 36 | -------------------------------------------------------------------------------- /error-boundary/src/components/Loading.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 23 | 24 | 43 | -------------------------------------------------------------------------------- /error-boundary/src/components/PostList.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 22 | -------------------------------------------------------------------------------- /error-boundary/src/global.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | export function NewGlobalEvent (eventName = '') { 4 | const bus = new Vue() 5 | const name = `global-${eventName}-event` 6 | 7 | function generic (action) { 8 | bus.$emit(name, action) 9 | } 10 | 11 | function show (payload = true) { 12 | generic({ type: 'SHOW', payload }) 13 | } 14 | 15 | function hide (payload = false) { 16 | generic({ type: 'HIDE', payload }) 17 | } 18 | 19 | function onToggle (callback) { 20 | bus.$on(name, callback) 21 | } 22 | 23 | function off () { 24 | bus.$off(name) 25 | } 26 | 27 | return { 28 | show, 29 | hide, 30 | off, 31 | onToggle 32 | } 33 | } 34 | 35 | export default { 36 | loading: NewGlobalEvent('loading'), 37 | modal: NewGlobalEvent('modal'), 38 | notification: NewGlobalEvent('notification') 39 | } 40 | -------------------------------------------------------------------------------- /error-boundary/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import services from './services' 4 | import global from './global' 5 | 6 | Vue.config.productionTip = false 7 | 8 | Object.defineProperty(Vue.prototype, '$services', { 9 | get () { 10 | return services 11 | }, 12 | set () { 13 | throw new Error('you cann\'t set $services') 14 | } 15 | }) 16 | 17 | Object.defineProperty(Vue.prototype, '$g', { 18 | get () { 19 | return global 20 | }, 21 | set () { 22 | throw new Error('you cann\'t set $g') 23 | } 24 | }) 25 | 26 | new Vue({ 27 | render: h => h(App) 28 | }).$mount('#app') 29 | -------------------------------------------------------------------------------- /error-boundary/src/services/index.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import PostsService from './posts' 3 | 4 | const httpClient = axios.create({ 5 | baseURL: 'https://jsonplaceholder.typicode.com' 6 | }) 7 | 8 | export default { 9 | posts: PostsService(httpClient) 10 | } 11 | -------------------------------------------------------------------------------- /error-boundary/src/services/posts.js: -------------------------------------------------------------------------------- 1 | import global from '../global' 2 | 3 | function getPosts (httpClient) { 4 | return new Promise((resolve, reject) => { 5 | try { 6 | setTimeout(async () => { 7 | const response = await httpClient.get('/posts') 8 | resolve(response) 9 | }, 3000) 10 | } catch (err) { 11 | reject(err) 12 | } 13 | }) 14 | } 15 | 16 | export default (httpClient) => ({ 17 | async getAll () { 18 | global.loading.show() 19 | const response = await getPosts(httpClient) 20 | global.loading.hide() 21 | return response 22 | } 23 | }) 24 | -------------------------------------------------------------------------------- /error-boundary/src/stores/posts.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | const state = Vue.observable({ 4 | posts: [], 5 | isLoading: false, 6 | hasError: false 7 | }) 8 | 9 | export const getPosts = () => state.posts 10 | export const isLoading = () => state.isLoading 11 | export const hasError = () => state.hasError 12 | 13 | export function setPosts (posts) { 14 | state.posts = posts 15 | } 16 | 17 | export function setLoading (loading) { 18 | state.isLoading = loading 19 | } 20 | 21 | export function setError (error) { 22 | state.hasError = error 23 | } 24 | -------------------------------------------------------------------------------- /error-boundary/src/stores/user.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | // State 4 | const state = Vue.observable({ 5 | currentUser: { 6 | id: '', 7 | name: '', 8 | email: '' 9 | } 10 | }) 11 | 12 | // Getters 13 | export const getCurrentUser = () => state.currentUser 14 | 15 | // Actions 16 | export function setEmail (email) { 17 | state.currentUser.email = email 18 | } 19 | 20 | export function setCurrentUser (user) { 21 | state.currentUser = user 22 | } 23 | -------------------------------------------------------------------------------- /factory-components/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /factory-components/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /factory-components/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: [ 7 | 'plugin:vue/essential', 8 | '@vue/standard' 9 | ], 10 | parserOptions: { 11 | parser: 'babel-eslint' 12 | }, 13 | rules: { 14 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 15 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /factory-components/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /factory-components/README.md: -------------------------------------------------------------------------------- 1 | # factory-components 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /factory-components/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /factory-components/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "factory-components", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "core-js": "^3.6.5", 12 | "vue": "^2.6.11" 13 | }, 14 | "devDependencies": { 15 | "@vue/cli-plugin-babel": "~4.5.0", 16 | "@vue/cli-plugin-eslint": "~4.5.0", 17 | "@vue/cli-service": "~4.5.0", 18 | "@vue/eslint-config-standard": "^5.1.2", 19 | "babel-eslint": "^10.1.0", 20 | "eslint": "^6.7.2", 21 | "eslint-plugin-import": "^2.20.2", 22 | "eslint-plugin-node": "^11.1.0", 23 | "eslint-plugin-promise": "^4.2.1", 24 | "eslint-plugin-standard": "^4.0.0", 25 | "eslint-plugin-vue": "^6.2.2", 26 | "lint-staged": "^9.5.0", 27 | "vue-template-compiler": "^2.6.11" 28 | }, 29 | "gitHooks": { 30 | "pre-commit": "lint-staged" 31 | }, 32 | "lint-staged": { 33 | "*.{js,jsx,vue}": [ 34 | "vue-cli-service lint", 35 | "git add" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /factory-components/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/factory-components/public/favicon.ico -------------------------------------------------------------------------------- /factory-components/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /factory-components/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 29 | -------------------------------------------------------------------------------- /factory-components/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/factory-components/src/assets/logo.png -------------------------------------------------------------------------------- /factory-components/src/components/Modal.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | 15 | 34 | -------------------------------------------------------------------------------- /factory-components/src/components/ModalFactory.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 19 | -------------------------------------------------------------------------------- /factory-components/src/components/ModalLogin.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | 15 | 34 | -------------------------------------------------------------------------------- /factory-components/src/components/ModalRegister.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | 15 | 34 | -------------------------------------------------------------------------------- /factory-components/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App) 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /global-services/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /global-services/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /global-services/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: [ 7 | 'plugin:vue/essential', 8 | '@vue/standard' 9 | ], 10 | parserOptions: { 11 | parser: 'babel-eslint' 12 | }, 13 | rules: { 14 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 15 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /global-services/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /global-services/README.md: -------------------------------------------------------------------------------- 1 | # vue-global-store 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /global-services/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /global-services/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-global-store", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.22.0", 12 | "core-js": "^3.6.5", 13 | "vue": "^2.6.11" 14 | }, 15 | "devDependencies": { 16 | "@vue/cli-plugin-babel": "~4.5.0", 17 | "@vue/cli-plugin-eslint": "~4.5.0", 18 | "@vue/cli-service": "~4.5.0", 19 | "@vue/eslint-config-standard": "^5.1.2", 20 | "babel-eslint": "^10.1.0", 21 | "eslint": "^6.7.2", 22 | "eslint-plugin-import": "^2.20.2", 23 | "eslint-plugin-node": "^11.1.0", 24 | "eslint-plugin-promise": "^4.2.1", 25 | "eslint-plugin-standard": "^4.0.0", 26 | "eslint-plugin-vue": "^6.2.2", 27 | "lint-staged": "^9.5.0", 28 | "vue-template-compiler": "^2.6.11" 29 | }, 30 | "gitHooks": { 31 | "pre-commit": "lint-staged" 32 | }, 33 | "lint-staged": { 34 | "*.{js,jsx,vue}": [ 35 | "vue-cli-service lint", 36 | "git add" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /global-services/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/global-services/public/favicon.ico -------------------------------------------------------------------------------- /global-services/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /global-services/src/App.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 48 | -------------------------------------------------------------------------------- /global-services/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/global-services/src/assets/logo.png -------------------------------------------------------------------------------- /global-services/src/components/Content.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 33 | -------------------------------------------------------------------------------- /global-services/src/components/Footer.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 36 | -------------------------------------------------------------------------------- /global-services/src/components/Header.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 36 | -------------------------------------------------------------------------------- /global-services/src/components/Loading.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 23 | 24 | 43 | -------------------------------------------------------------------------------- /global-services/src/global.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | export function NewGlobalEvent (eventName = '') { 4 | const bus = new Vue() 5 | const name = `global-${eventName}-event` 6 | 7 | function generic (action) { 8 | bus.$emit(name, action) 9 | } 10 | 11 | function show (payload = true) { 12 | generic({ type: 'SHOW', payload }) 13 | } 14 | 15 | function hide (payload = false) { 16 | generic({ type: 'HIDE', payload }) 17 | } 18 | 19 | function onToggle (callback) { 20 | bus.$on(name, callback) 21 | } 22 | 23 | function off () { 24 | bus.$off(name) 25 | } 26 | 27 | return { 28 | show, 29 | hide, 30 | off, 31 | onToggle 32 | } 33 | } 34 | 35 | export default { 36 | loading: NewGlobalEvent('loading'), 37 | modal: NewGlobalEvent('modal'), 38 | notification: NewGlobalEvent('notification') 39 | } 40 | -------------------------------------------------------------------------------- /global-services/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import services from './services' 4 | import global from './global' 5 | 6 | Vue.config.productionTip = false 7 | 8 | Object.defineProperty(Vue.prototype, '$services', { 9 | get () { 10 | return services 11 | }, 12 | set () { 13 | throw new Error('you cann\'t set $services') 14 | } 15 | }) 16 | 17 | Object.defineProperty(Vue.prototype, '$g', { 18 | get () { 19 | return global 20 | }, 21 | set () { 22 | throw new Error('you cann\'t set $g') 23 | } 24 | }) 25 | 26 | new Vue({ 27 | render: h => h(App) 28 | }).$mount('#app') 29 | -------------------------------------------------------------------------------- /global-services/src/services/index.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import PostsService from './posts' 3 | 4 | const httpClient = axios.create({ 5 | baseURL: 'https://jsonplaceholder.typicode.com' 6 | }) 7 | 8 | export default { 9 | posts: PostsService(httpClient) 10 | } 11 | -------------------------------------------------------------------------------- /global-services/src/services/posts.js: -------------------------------------------------------------------------------- 1 | import global from '../global' 2 | 3 | function getPosts (httpClient) { 4 | return new Promise((resolve, reject) => { 5 | try { 6 | setTimeout(async () => { 7 | const response = await httpClient.get('/posts') 8 | resolve(response) 9 | }, 3000) 10 | } catch (err) { 11 | reject(err) 12 | } 13 | }) 14 | } 15 | 16 | export default (httpClient) => ({ 17 | async getAll () { 18 | global.loading.show() 19 | const response = await getPosts(httpClient) 20 | global.loading.hide() 21 | return response 22 | } 23 | }) 24 | -------------------------------------------------------------------------------- /global-services/src/stores/posts.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | const state = Vue.observable({ 4 | posts: [], 5 | isLoading: false, 6 | hasError: false 7 | }) 8 | 9 | export const getPosts = () => state.posts 10 | export const isLoading = () => state.isLoading 11 | export const hasError = () => state.hasError 12 | 13 | export function setPosts (posts) { 14 | state.posts = posts 15 | } 16 | 17 | export function setLoading (loading) { 18 | state.isLoading = loading 19 | } 20 | 21 | export function setError (error) { 22 | state.hasError = error 23 | } 24 | -------------------------------------------------------------------------------- /global-services/src/stores/user.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | // State 4 | const state = Vue.observable({ 5 | currentUser: { 6 | id: '', 7 | name: '', 8 | email: '' 9 | } 10 | }) 11 | 12 | // Getters 13 | export const getCurrentUser = () => state.currentUser 14 | 15 | // Actions 16 | export function setEmail (email) { 17 | state.currentUser.email = email 18 | } 19 | 20 | export function setCurrentUser (user) { 21 | state.currentUser = user 22 | } 23 | -------------------------------------------------------------------------------- /scoped-slots/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /scoped-slots/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /scoped-slots/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: [ 7 | 'plugin:vue/essential', 8 | '@vue/standard' 9 | ], 10 | parserOptions: { 11 | parser: 'babel-eslint' 12 | }, 13 | rules: { 14 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 15 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scoped-slots/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /scoped-slots/README.md: -------------------------------------------------------------------------------- 1 | # scoped-slots 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /scoped-slots/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /scoped-slots/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scoped-slots", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.22.0", 12 | "core-js": "^3.6.5", 13 | "vue": "^2.6.11" 14 | }, 15 | "devDependencies": { 16 | "@vue/cli-plugin-babel": "~4.5.0", 17 | "@vue/cli-plugin-eslint": "~4.5.0", 18 | "@vue/cli-service": "~4.5.0", 19 | "@vue/eslint-config-standard": "^5.1.2", 20 | "babel-eslint": "^10.1.0", 21 | "eslint": "^6.7.2", 22 | "eslint-plugin-import": "^2.20.2", 23 | "eslint-plugin-node": "^11.1.0", 24 | "eslint-plugin-promise": "^4.2.1", 25 | "eslint-plugin-standard": "^4.0.0", 26 | "eslint-plugin-vue": "^6.2.2", 27 | "lint-staged": "^9.5.0", 28 | "vue-template-compiler": "^2.6.11" 29 | }, 30 | "gitHooks": { 31 | "pre-commit": "lint-staged" 32 | }, 33 | "lint-staged": { 34 | "*.{js,jsx,vue}": [ 35 | "vue-cli-service lint", 36 | "git add" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /scoped-slots/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/scoped-slots/public/favicon.ico -------------------------------------------------------------------------------- /scoped-slots/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /scoped-slots/src/App.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 44 | 45 | 72 | -------------------------------------------------------------------------------- /scoped-slots/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/scoped-slots/src/assets/logo.png -------------------------------------------------------------------------------- /scoped-slots/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 41 | 42 | 43 | 59 | -------------------------------------------------------------------------------- /scoped-slots/src/components/QueryRenderer.vue: -------------------------------------------------------------------------------- 1 | 50 | -------------------------------------------------------------------------------- /scoped-slots/src/components/WithMouse.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 22 | -------------------------------------------------------------------------------- /scoped-slots/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App) 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /scoped-slots/src/services/index.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import PostsService from './posts' 3 | 4 | const httpClient = axios.create({ 5 | baseURL: 'https://jsonplaceholder.typicode.com' 6 | }) 7 | 8 | export default { 9 | posts: PostsService(httpClient) 10 | } 11 | -------------------------------------------------------------------------------- /scoped-slots/src/services/posts.js: -------------------------------------------------------------------------------- 1 | export default (httpClient) => ({ 2 | getAll () { 3 | return httpClient.get('/posts') 4 | } 5 | }) 6 | -------------------------------------------------------------------------------- /vue-global-store/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /vue-global-store/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /vue-global-store/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: [ 7 | 'plugin:vue/essential', 8 | '@vue/standard' 9 | ], 10 | parserOptions: { 11 | parser: 'babel-eslint' 12 | }, 13 | rules: { 14 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 15 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vue-global-store/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /vue-global-store/README.md: -------------------------------------------------------------------------------- 1 | # vue-global-store 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /vue-global-store/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /vue-global-store/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-global-store", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.22.0", 12 | "core-js": "^3.6.5", 13 | "vue": "^2.6.11" 14 | }, 15 | "devDependencies": { 16 | "@vue/cli-plugin-babel": "~4.5.0", 17 | "@vue/cli-plugin-eslint": "~4.5.0", 18 | "@vue/cli-service": "~4.5.0", 19 | "@vue/eslint-config-standard": "^5.1.2", 20 | "babel-eslint": "^10.1.0", 21 | "eslint": "^6.7.2", 22 | "eslint-plugin-import": "^2.20.2", 23 | "eslint-plugin-node": "^11.1.0", 24 | "eslint-plugin-promise": "^4.2.1", 25 | "eslint-plugin-standard": "^4.0.0", 26 | "eslint-plugin-vue": "^6.2.2", 27 | "lint-staged": "^9.5.0", 28 | "vue-template-compiler": "^2.6.11" 29 | }, 30 | "gitHooks": { 31 | "pre-commit": "lint-staged" 32 | }, 33 | "lint-staged": { 34 | "*.{js,jsx,vue}": [ 35 | "vue-cli-service lint", 36 | "git add" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /vue-global-store/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/vue-global-store/public/favicon.ico -------------------------------------------------------------------------------- /vue-global-store/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /vue-global-store/src/App.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 46 | -------------------------------------------------------------------------------- /vue-global-store/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IgorHalfeld/codecon-vuejs-components-patterns-workshop/48b9e8cc9890bffc6e52933e32077eb5939ad357/vue-global-store/src/assets/logo.png -------------------------------------------------------------------------------- /vue-global-store/src/components/Content.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 33 | -------------------------------------------------------------------------------- /vue-global-store/src/components/Footer.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 36 | -------------------------------------------------------------------------------- /vue-global-store/src/components/Header.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 | 36 | -------------------------------------------------------------------------------- /vue-global-store/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App) 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /vue-global-store/src/services/index.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import PostsService from './posts' 3 | 4 | const httpClient = axios.create({ 5 | baseURL: 'https://jsonplaceholder.typicode.com' 6 | }) 7 | 8 | export default { 9 | posts: PostsService(httpClient) 10 | } 11 | -------------------------------------------------------------------------------- /vue-global-store/src/services/posts.js: -------------------------------------------------------------------------------- 1 | 2 | export default (httpClient) => ({ 3 | getAll () { 4 | return httpClient.get('/posts') 5 | } 6 | }) 7 | -------------------------------------------------------------------------------- /vue-global-store/src/stores/posts.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | const state = Vue.observable({ 4 | posts: [], 5 | isLoading: false, 6 | hasError: false 7 | }) 8 | 9 | export const getPosts = () => state.posts 10 | export const isLoading = () => state.isLoading 11 | export const hasError = () => state.hasError 12 | 13 | export function setPosts (posts) { 14 | state.posts = posts 15 | } 16 | 17 | export function setLoading (loading) { 18 | state.isLoading = loading 19 | } 20 | 21 | export function setError (error) { 22 | state.hasError = error 23 | } 24 | -------------------------------------------------------------------------------- /vue-global-store/src/stores/user.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | 3 | // State 4 | const state = Vue.observable({ 5 | currentUser: { 6 | id: '', 7 | name: '', 8 | email: '' 9 | } 10 | }) 11 | 12 | // Getters 13 | export const getCurrentUser = () => state.currentUser 14 | 15 | // Actions 16 | export function setEmail (email) { 17 | state.currentUser.email = email 18 | } 19 | 20 | export function setCurrentUser (user) { 21 | state.currentUser = user 22 | } 23 | --------------------------------------------------------------------------------