Background:
In ES6 we now have `Object.setPrototypeOf` which makes prototype delegation an alternative to *sugary*, fake class coding patterns. This can be accomplished in ES5, but ES6 is much more elegant. Here is a basic example. `new` is never used and `this` is very easy to follow.
Working example with changes to mithril.js on lines 854, 858, 859 *only*.
http://jsbin.com/nopugo/1/edit?js,console,output
```javascript
'use strict'
const m = require('mithril')
const DataModel = {
data: [1,2,3],
getData(){
console.log('getting data from server')
return this.data
},
postData(val){
console.log('sending data to server')
this.data.push(val)
}
}
const ViewModel = {
filterEvenData: function() {
return this.getData().filter((val) => (val % 2 === 0) && (+val !== 0))
},
addNewData: function(val){
console.log('adding new data', val)
this.postData(val)
}
}
var Model = Object.setPrototypeOf(ViewModel, DataModel)
const App = {
controller(){},
view(ctrl){
return m('div', [
m('pre', [ 'EVEN NUMBERS IN DATA\n',
this.filterEvenData().map((key,i) =>`${i+1} = ${key}\n`)
]),
m('div', 'Enter a number'),
m('input[placeholder=number]', {
// addNewData is called with **this** === undefined unless we pass `this` to Function.prototype.call in m.withAttr
onchange: m.withAttr('value', App.addNewData, App),
value: null
}
)
])
}
}
Object.setPrototypeOf(App, Model)
m.mount(document.body, App)
```
When a null component is passed into m.mount(), remove references to the root DOM element from:
- roots
- cellCache
- nodeCache
And remove the associated entries from:
- controllers
- components
By "fixed", I mean "screwed up, not at all following the correct version
number, and refusing to ask on Gitter what the correct version really is, and
just assuming the wrong version despite hints all over the source screaming
'THIS IS THE CORRECT VERSION, YOU STUPID IDIOT!!!'".
I feel that should be a relatively accurate explanation of the mistake I made
while working on this patch (the specific commit that introduced it was
squashed in rebasing, and another commit was easier than a revert, since the
one that introduced it also entailed a few other things).
This is in preparation for a PR, to reduce potential for merge conflicts
with either my PR or others', since mine will modify a large amount of
the main file.
1. Do some temporary style modifications to help make the code more readable
for profiling (with help from ESLint).
2. Profile the code, and optimize accordingly.