1 VueJS #2 News from Amsterdam & Vuex Contact: Temitope Faro @topriddy Jason Staerck @jasonstaerck Emanuell Minciu @EmanuellMinciu Adam Spencer @MSMGroupcareers Follow as @vuejsmcr
2 Agenda • Recap • Playback from VueJS Amsterdam • State Management with Vuex • Wrap up
3 Recap
4 Newsletters • Vue.js News • Vue.js Feed • Vue.js Developers
5 Playback from VueJS Amsterdam
6 What have we been up to?
7 Evan You Edd Yerburgh Eduardo San Martin Morote Alex & Sebastien Chopin Sarah Drasner Gerard Sans Guillaume Chau Plamen Zdravkov Ives Van Hoorne Jen Looper Roman Kuba
8 @vue/cli 3.0 Demo
9 Create an engaging mobile app with NativeScript and Vue.js Jen Looper Senior Developer Advocate, Progress Co-Founder: Wellesley Chinese Language School
10 ? A framework for building native cross-platform mobile apps No-compromise, smoothly-animating native mobile apps for iOS and Android
11 Use JavaScript, CSS, XML to build your app
12 Why Vue for mobile? • Native mobile rendering with Vue’s adoption of a virtual DOM • Great way for web developers to embrace mobile platforms • Vue is lightweight • NativeScript and Vue have great code-sharing potential!
13 NATIVESCRIPT-VUE 1.0
14 Basic Differences <web> import Vue from 'vue'; {NativeScript} import Vue from 'nativescript-vue'; <web> {NativeScript} <web> {NativeScript}
15 Example: Build for android, iOS, web in one repo!
16 Entry Points web mobile
17 App.vue web + mobile
18 https://play.nativescript.org/?template=play- vue&id=KwPJ7b&v=3
19 Unit testing Vue components The what, why, and how Edd Yerburgh Vue.js core team member
20 Why should we write unit tests? • Check that the components work correctly • Provide documentation • Easier debugging • Less bugs
21 Component Input Output
22 vue-test-utils $ npm install --save-dev @vue/test-utils Jest $ npm install --save-dev jest vue-jest babel-jest
23 Inside Modal.vue <template> <div v-if="visible"> <button @click="onClose" /> </div> </template>
24 Mount import { mount } from '@vue/test-utils’ import Modal from '../Modal.vue’ const wrapper = mount(Modal)
25 test('does not render when not passed visible prop', () => { const wrapper = mount(Modal) expect(wrapper.isEmpty()).toBe(true) })
26 test('renders when passed visible prop as true', () => { const wrapper = mount(Modal, { propsData: { visible: true } }) expect(wrapper.isEmpty()).toBe(false) })
27 test('calls onClose when button is clicked', () => { const onClose = jest.fn() const wrapper = mount(Modal, { propsData: { visible: true, onClose } }) wrapper.find('button').trigger('click') expect(onClose).toHaveBeenCalled() })
28 Success! 
29 Fail 
30 test('renders correctly', () => { const wrapper = mount(Modal, { propsData: { visible: true } }) expect(wrapper.isEmpty()).toBe(false) }) expect(wrapper.html()).toMatchSnapshot() Snapshot test
31 Does previous snapshot exist? Create snapshot Does output match snapshot? Test passesTest fails Yes No YesNo
32 After the first test run
33 DOCS! vue-test-utils.vuejs.org
34 State animations Eduardo San Martin Morote Vue core team member Author of VueFire 2, VueMotion, VueTweezing Vue instructor around Europe
35 http://slides.com/posva/state-animations
36 When should we use animations? • The user does something • We need the user’s attention • We want to make things fun
37
38 State animations • Boolean toggling • Easings • Physics
39 Vue Tweezing
40 Vue Tweezing <Tweezing :to="1” tween="custom” :time="mouseYPer"> <div slot-scope="value"> <pre>{{ value }}</pre> <div class="ball" :style="ballStyle(value)"></div> </div> </Tweezing>
41 Vue Motion
42 Vue Motion <Motion :values="positions" spring="wobbly"> <template slot-scope="positions"> <div v-for="cell in cells” :style="{ transform: `translate( ${positions[cell.id].x}px, ${positions[cell.id].y}px) `}” > {{ cell.number }} </div> </template> </Motion>
43 http://slides.com/posva/state-animations
44 Thank you 
45 Roman Kuba Scaling Vue.js in an existing stack @codeship @codebryo
46 It’s not always a greenfield project
47 What, Why & how •Adding new tech is always an INVESTMENT •Competing tech will run in parallel •A full SPA is probably not possible at all •Split the process into phases
48 Phase 1 Reduce all the things
49 Phase 2 Introduce Vue.js
50 Phase 3 Better build-process
51 Phase 3 Better build-process
52 ARE YOU READY
53 Phase 4 Build a SPA
54 Phase 4 Build a SPA
55 Phase 5 Getting ready to scale
56 Conclusion Happy developers 
57 VUE DEVELOPMENT IN CODESANDBOX IVES VAN HOORNE @compuives @codesandboxap p
58 Not this
59 Jason staerck @jasonstaerck Questions?
60 State Management with Vuex
61 Introduction to State Management State management is a core requirement for building modern day frontend applications There is a need to manage data flow in the application across various components, communication to backend systems, internal updates, etc. A good modern frontend framework is expected to provide a clear way of managing the application state
62 Introduction to State Management • contacts • messages • profile • call logs • stories? Chat app Weather app Price comparison • cities • days • weather • questions • answers • profile
63 Introduction to State Management • Locally managing data within components • Managing data using the Event Bus • Using Vuex
64 Locally managing data within components Counter Example
65 Locally managing data within components
66 Locally managing data within components Products Example – Passing data to child components via props
67 Locally managing data within components Order Summary Example – Passing data to child components via props
68 Introduction to State Management • Locally managing data within components • Managing data using the Event Bus • Using Vuex • Locally managing data within components
69 Managing Data using Event Bus • Uses Vue Event system • Does not require direct parent/child relationship • Components typically communicate by emitting and listening on events
70 Vuex – Event Bus
71 Managing Data using Event Bus • Uses Vue Event system • Does not require direct parent/child relationship • Components typically communicate by emitting and listening on events
72 Managing Data using Event Bus Products Example
73 Managing Data using Event Bus Products Example
74 Live Demo
75 Managing Data using Event Bus Advantages Disadvantages • Less coupled • Data can shared/communicated beyond parent/child relationship • Initially easy to setup • Difficult to maintain in large applications • Different components may duplicate same data • Difficult to debug
76 Introduction to State Management • Locally managing data within components • Managing data using the Event Bus • Using Vuex • Managing data using the Event Bus
77 Vuex • Is defined in the official documentation as both a state management pattern + library for Vuejs apps. • Basically serves as a centralized store for all the components in an application making sure that state can only be mutated in a predictable fashion. • Vuex is an implementation of the Flux architecture
78 Vuex – centralized store
79 Vuex – Flux Principles • #1: Single source of truth • #2: Data is read only • #3: Mutations are read synchronous  Vuex implements above Flux principles, hence, ensuring data is kept in a predictable state while it is being shared across multiple components
80 Vuex – Why Flux? Facebook invented flux application design pattern to deal with the very evasive Zombie notification bug in their application.
81 Vuex – Features • centralized store • reactivity on any component reading store data • custom mutations • hot module reloading • time travel debugging
82 Vuex – Counter Example (revisited)
83 Vuex – Products example (revisited)
84 Live Demo
85 Vuex – Core Features • state: centralized store • custom getters • custom mutations • custom actions
86 Vuex – State • is an object tree that represents the state of the application • mapState helper for mapping multiple states
87 Vuex – Getters Used for computing derived states
88 Vuex – Mutations • Mutations is the only way to change state in the Vuex store. • Each mutation has a string type and a handler • Has to be synchronous
89 Vuex – Mutations mapMutations helper
90 Things not covered • Actions • Modules • Vuex-map-fields library for mapping form fields – 2-way data-binding
91 When to use Vuex “Flux libraries are like glasses: you’ll know when you need them.” – Dan Abramov (author of Redux)
92 Questions?
93 Thank you 
94 Resources https://github.com/Tyki/VueJSAmsterdam-Slides Videos + Slides + Demos
9595 Wrap Up • Slides hosted: • Next Meetup to be scheduled – mid April • Want to get involved? – get in touch with us! • Looking to get some Vue core team members / contributors
96 Edd Yerburgh Gerard Sans Speakers
97 Skype Q&A Session
98 VueJS #2 News from Amsterdam & Vuex Contact: Temitope Faro @topriddy Jason Staerck @ jasonstaerck Emanuell Minciu @EmanuellMinciu Adam Spencer @MSMGroupcareers Follow as @vuejsmcr

Vue.js - AMS & Vuex

Editor's Notes

  • #2 How many of you are here for the first time?
  • #3 Hello & Welcome Fire & Safety Running through the Agenda Introducing speakers
  • #4 Tope to make use of Vue Devtools as part of his talk. Any questions / things you would like us to cover leave a comment.
  • #5 Vue.JS news has podcasts.
  • #6 Anyone here today has been to the conference?
  • #95 Future conferences and disconts
  • #96 Topics for next meetups: Unit Testing with Jest Server side Validation with VeeValidate CSS with Vue Routing Guest speakers