London Web Standards / #lwsVue / @blakenewman
Plan A
Plan V
Frameworks...
Task Runner tools...
Build tools...
All the things™...
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
Imperative JavaScript
Declarative CSS
HTML
London Web Standards / #lwsVue / @blakenewman
JavaScript is Fragile
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
https://addyosmani.com/scalablejs/
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
(Try to Stick to DRY)
London Web Standards / #lwsVue / @blakenewman
Dependency Management
Sacrificial Architecture
Keep in control
Development experience
London Web Standards / #lwsVue / @blakenewman
{
"name": "sample-package-json",
"dependencies": {
"babel-runtime": "^6.0.0",
"vue": "^1.0.0",
"vue-resource": "^0.8.0",
"vue-router": "^0.7.0",
"vuex": "^0.6.0",
"vuex-router-sync": "^1.0.0"
}
}
https://docs.npmjs.com/misc/semver
London Web Standards / #lwsVue / @blakenewman
^1.0.0
1.0.0 <= 2.0.0
=
London Web Standards / #lwsVue / @blakenewman
1.0.x
1.0.0 <= 1.1.0
=
London Web Standards / #lwsVue / @blakenewman
1.0.17
1.0.17
=
$ npm i -g npm-check-updates
London Web Standards / #lwsVue / @blakenewman
$ ncu
eslint 2.12.x → 2.13.x
vue-hot-reload-api 1.3.x → 2.0.x
London Web Standards / #lwsVue / @blakenewman
Module A
Module B
Module C
Store
State
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
Module A
Module B
Module C
Store
State A
State B
State C
London Web Standards / #lwsVue / @blakenewman
Initialisation performance
Designate entry points
Asynchronous code
Fixes: “Monolithic bundle” and “Unmaintainable manual imports”
require.ensure([ './basket.vue' ], (require) => {
require([ './basket.vue' ], resolve);
}, 'basket');
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
Choose your framework as if you will need to change it after six months
Don't be a slave to Frameworks
London Web Standards / #lwsVue / @blakenewman
// getUsers factory
getUsers.$inject = ['$http'];
function getUsers($http) {
return $http.get('api/v1/users');
}
app.factory('getUsers', getUsers);
// Home controller
homeController.$inject = ['$scope', 'getUsers'];
function homeController($score, getUsers) {
getUsers().then(response => {
$scope.users = response.data;
});
}
app.controller('home', homeController);
London Web Standards / #lwsVue / @blakenewman
// getUsers es6 module
export default function(){
return fetch('api/v1/users').then(function (response) {
return response.json();
});
};
// Home controller
import getUsers from './getUsers';
homeController.$inject = ['$scope'];
function homeController($scope) {
getUsers().then(users => {
$scope.users = users;
});
}
app.controller('home', homeController);
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
The best code that you can write now, probably won't be in a few years
London Web Standards / #lwsVue / @blakenewman
The best way to cope with change is to increase productivity
Patch part of dependency tree with the new code
Changes appear live without page reloading
Compiler
HMR Server
Bundle Server
Compile
Change
code
HMR runtime
bundle
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
Hiring people to write is not the same as hiring people to design and build durable, usable, dependable software.
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
Library for the View layer
Components with reactivity
Extendable via plugins
Lightweight
Simplicity
Testable
London Web Standards / #lwsVue / @blakenewman
Reactive data-binding system for a Data-driven view
DOM in sync with data
Object.defineProperty
London Web Standards / #lwsVue / @blakenewman
Component System helps with small abstraction layer
Component loosely modeled after the Web Components spec
Implements the Slot API and the special attribute is
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
Comp A
Comp B
Module A
Store
State Module A
State Module B
London Web Standards / #lwsVue / @blakenewman
Actions
London Web Standards / #lwsVue / @blakenewman
// getUsers es6 module
export default function(){
return fetch('api/v1/users').then(function (response) {
return response.json();
});
};
// Vue component script
import getUsers from './getUsers';
export default {
data() {
return {
users: [ ]
}
},
created() {
getUsers().then(users => {
this.users = users;
});
}
};
London Web Standards / #lwsVue / @blakenewman
Vue.component('demo-component', {
template: '<div> {{ msg }} </div>',
// Data initialization
data() {
return {
msg: 'Vue is cool'
};
},
computed: { },
methods: { },
events: { },
ready() {
// Execute logic on ready hook
},
});
// -------
<demo-component></demo-component>
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
London Web Standards / #lwsVue / @blakenewman
const vnode = {
tag: 'div',
children: [
{ tag: 'my-component' }
]
};
<div>
<my-component></my-component>
</div>
London Web Standards / #lwsVue / @blakenewman
Chat to me on twitter: @blakenewman
OR
Chat to me in the real world :)