Background of Vue.js
Inbuilt features of Vue.js
Reactivity Systems
Templates, are they bad?
The future of Vue's internals
Plus much more from alternative avenues
Declaritive Rendering
Component
System
Core
Routing
vue-router
State management
vuex
Build system
vue-loader
vue-cli
SSR / Native / Extensions
Ecosystem
<body>
</body>
<body>
<div id="app">
</div>
</body>
<body>
<div id="app">
</div>
<script src="https://unpkg.com/vue"></script>
<script>
new Vue({
});
</script>
</body>
<body>
<div id="app">
</div>
<script src="https://unpkg.com/vue"></script>
<script>
new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
});
</script>
</body>
<body>
<div id="app">
</div>
<script src="https://unpkg.com/vue"></script>
</body>
<body>
<div id="app">
</div>
<script src="https://unpkg.com/vue"></script>
<script>
new Vue({
el: '#app'
});
</script>
</body>
<body>
<div id="app">
{{ message }}
</div>
<script src="https://unpkg.com/vue"></script>
<script>
new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
});
</script>
</body>
CSS Modules
<template>
<p class="red">
{{ message }}
</p>
</template>
<template>
<p class="red">
{{ message }}
</p>
</template>
<script>
export default {
data() {
return {
message: 'Hello world!'
};
}
};
</script>
<template>
<p class="red">
{{ message }}
</p>
</template>
<script>
export default {
data() {
return {
message: 'Hello world!'
};
}
};
</script>
<style>
.red {
colour: red;
}
</style>
<template lang="pug">
p.red {{ message }}
</template>
<script lang="ts">
import Vue from 'vue'
import Component from 'vue-class-component'
@Component
export default class MyComponent extends Vue {
message: string = 'Hello world!'
}
</script>
<style lang="styl">
.red
colour red
</style>
<template>
<p class="red"></p>
</template>
<style>
.red {
colour: red;
}
</style>
<p class="red" data-v-f3f3eg9></p>
<style>
.red[data-v-f3f3eg9] {
color: red;
}
</style>
<template>
<p class="red"></p>
</template>
<style scoped>
.red {
colour: red;
}
</style>
<template>
<p :class="$style.red"></p>
</template>
<style>
.red {
colour: red;
}
</style>
<div class="_1VyoJ-uZOjlOxP7jWUy19_0"></div>
<style>
._1VyoJ-uZOjlOxP7jWUy19_0 {
color: red;
}
</style>
<template>
<p :class="$style.red"></p>
</template>
<style module>
.red {
colour: red;
}
</style>
Compiler
HMR Server
Bundle Server
Compile
Change
code
HMR runtime
bundle
View
class Child {
props = ['message', 'enabled'],
render() {
<div>{
this.enabled ? this.message : 'I am disabled'
}</div>
}
}
class Parent {
message = 'Hello world!'
enabled = false
render() {
return (
<div>
<Child message={this.message} enabled={!!this.message} />
<Child message={this.message} enabled={this.enabled} />
</div>
)
}
}
const vm = new Parent()
vm.message = ''
Explicit pull signal from developer
Manual optimisation hints from developer
Simplified with immutable data
class Child {
props = ['message', 'enabled'],
render() {
<div>{
this.enabled ? this.message : 'I am disabled'
}</div>
}
}
class Parent {
message = 'Hello world!'
enabled = false
render() {
return (
<div>
<Child message={this.message} enabled={!!this.message} />
<Child message={this.message} enabled={this.enabled} />
</div>
)
}
}
const vm = new Parent()
vm.message = ''
Memory overhead, proportional to dataset size
Asynchronous and batches updates
Improved by skipping observation of immutable data
Improved by reducing computation granularity
class Child {
props = ['message', 'enabled'],
render() {
<div>{
this.enabled ? this.message : 'I am disabled'
}</div>
}
}
class Parent {
message = 'Hello world!'
enabled = false
render() {
return (
<div>
<Child message={this.message} enabled={!!this.message} />
<Child message={this.message} enabled={this.enabled} />
</div>
)
}
}
const vm = new Parent()
vm.message = ''
Explicit pull signal from developer
Manual optimisation hints from developer
Simplified with immutable data
Memory overhead, proportional to dataset size
Asynchronous and batches updates
Improved by skipping observation of immutable data
Improved by reducing computation granularity
Angular 5 - onPush with Observables
React + MobX
Vue 2 + Immutable data
<template>
<p>{{ message }}</p>
</template>
function render() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c('p', [
_vm._v(_vm._s(_vm.message))
])
}
function render() {
return (
<div>{ this.message }</div>
)
}
{
class: {
foo: true,
bar: false
},
style: {
color: 'red',
fontSize: '14px'
},
attrs: {
id: 'foo'
},
props: {
myProp: 'bar'
},
on: {
click: this.clickHandler
},
// ...
}
function render() {
return React.createElement(
"div",
null,
this.items.map(function (item) {
return React.createElement("p", null, item);
}),
React.createElement("p", null, this.message)
)
}
function render() {
return (
<div>
{ this.items.map(item => <p>{ item }</p>) }
<p>{ this.message }</p>
</div>
)
}
[node, [node, ...], node]
<template>
<div>
<p v-for="item in items">{{ item }}</p>
<p>{{ message }}</p>
</div>
</template>
function render() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c('div', [_vm._l((_vm.items), function(item) {
return _c('p', [_vm._v(_vm._s(item))])
}), _c('p', [_vm._v(_vm._s(_vm.message))])], 2)
}
<template>
<div>
<span>Static content</span>
<span>More static content</span>
</div>
</template>
function render() {
return (
<div>
<h2>Static content</h2>
<p>More static content</p>
</div>
)
}
function render() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _vm._m(0)
}
function render() {
return React.createElement(
"div",
null,
React.createElement("span", null, "Static content"),
React.createElement("span", null, "More static content")
)
}
Render (JSX)
Templates
Declarative with JSX
Presentational
Logical
HTML + small DSL
Child normalization
Declarative
Power of JavaScript
No DSL?
Static node hoisting
Progressive code updates
Closer to compiler
Various updates and improvements
- error handling
- functional components
- SSR
Possible support for Native Map & Set types to be supported for reactivity
Will be targeting evergreen browsers only in order to leverage native ES2015 features
Reactivity system will be rewritten with Proxies with various improvements
No major breaking changes; will be maintained in parallel to 2.x with feature parity
The Proxy object is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).
Vue.js currently has a few caveat when tracking changes
- Array length change detection
- New property detection
- Delete property detection
Proxies allow us to detect all these type of mutations
Planned to move the internals of Vue.js to TypeScript:
- Heavily risen in popularity
- Improved code readability
- Stricter Typing
- Ensures code is as monophonic as possible
- Helps us produce better Typescript support as standard