Merge branch 'next' into components
This commit is contained in:
commit
dab565727c
5 changed files with 45 additions and 17 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Subtree directives](#subtree directives)
|
- [Subtree directives](#subtree-directives)
|
||||||
- [Signature](#signature)
|
- [Signature](#signature)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
@ -60,7 +60,7 @@ This mechanism is only intended to be used as a last resort optimization tool. I
|
||||||
|
|
||||||
The example below shows how to use a SubtreeDirective object to create a static header that doesn't incur diff costs once it has been rendered. This means that we are avoiding the creation of the header subtree (and therefore skipping the diff algorithm) altogether, but it also means that dynamic variables will NOT be updated within the header.
|
The example below shows how to use a SubtreeDirective object to create a static header that doesn't incur diff costs once it has been rendered. This means that we are avoiding the creation of the header subtree (and therefore skipping the diff algorithm) altogether, but it also means that dynamic variables will NOT be updated within the header.
|
||||||
|
|
||||||
```
|
```javascript
|
||||||
var app = {}
|
var app = {}
|
||||||
|
|
||||||
//here's an example plugin that determines whether data has changes.
|
//here's an example plugin that determines whether data has changes.
|
||||||
|
|
@ -78,7 +78,7 @@ app.bindOnce = (function() {
|
||||||
|
|
||||||
//here's the view
|
//here's the view
|
||||||
app.view = function() {
|
app.view = function() {
|
||||||
m(".layout", [
|
return m(".layout", [
|
||||||
app.bindOnce(function() {
|
app.bindOnce(function() {
|
||||||
//this only runs once in order to boost performance
|
//this only runs once in order to boost performance
|
||||||
//dynamic variables are not updated here
|
//dynamic variables are not updated here
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
- [Casting the Response Data to a Class](#casting-the-response-data-to-a-class)
|
- [Casting the Response Data to a Class](#casting-the-response-data-to-a-class)
|
||||||
- [Unwrapping Response Data](#unwrapping-response-data)
|
- [Unwrapping Response Data](#unwrapping-response-data)
|
||||||
- [Using Different Data Transfer Formats](#using-different-data-transfer-formats)
|
- [Using Different Data Transfer Formats](#using-different-data-transfer-formats)
|
||||||
- [File uploads with FormData](#file-uploads-with-form-data)
|
- [File uploads with FormData](#file-uploads-with-formdata)
|
||||||
- [Using variable data formats](#using-variable-data-formats)
|
- [Using variable data formats](#using-variable-data-formats)
|
||||||
- [Extracting Metadata from the Response](#extracting-metadata-from-the-response)
|
- [Extracting Metadata from the Response](#extracting-metadata-from-the-response)
|
||||||
- [Custom request rejections](#custom-request-rejections)
|
- [Custom request rejections](#custom-request-rejections)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
- [Running clean up code on route change](#running-clean-up-code-on-route-change)
|
- [Running clean up code on route change](#running-clean-up-code-on-route-change)
|
||||||
- [Redirecting](#redirecting)
|
- [Redirecting](#redirecting)
|
||||||
- [Reading the currently active route](#reading-the-currently-active-route)
|
- [Reading the currently active route](#reading-the-currently-active-route)
|
||||||
- [Mode abstraction](#mode abstraction)
|
- [Mode abstraction](#mode-abstraction)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,13 +138,15 @@ var m = (function app(window, undefined) {
|
||||||
existing[cached[i].attrs.key] = {action: DELETION, index: i}
|
existing[cached[i].attrs.key] = {action: DELETION, index: i}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = data.filter(function(x) {return x != null})
|
||||||
|
|
||||||
var guid = 0
|
var guid = 0
|
||||||
for (var i = 0, len = data.length; i < len; i++) {
|
for (var i = 0, len = data.length; i < len; i++) {
|
||||||
if (data[i] && data[i].attrs && data[i].attrs.key == null) data[i].attrs.key = "__mithril__" + guid++
|
if (data[i] && data[i].attrs && data[i].attrs.key == null) data[i].attrs.key = "__mithril__" + guid++
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldMaintainIdentities) {
|
if (shouldMaintainIdentities) {
|
||||||
if (data.indexOf(null) > -1) data = data.filter(function(x) {return x != null})
|
|
||||||
|
|
||||||
var keysDiffer = false
|
var keysDiffer = false
|
||||||
if (data.length != cached.length) keysDiffer = true
|
if (data.length != cached.length) keysDiffer = true
|
||||||
else for (var i = 0, cachedCell, dataCell; cachedCell = cached[i], dataCell = data[i]; i++) {
|
else for (var i = 0, cachedCell, dataCell; cachedCell = cached[i], dataCell = data[i]; i++) {
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,32 @@ function testMithril(mock) {
|
||||||
test(function() {return m("div", [1], [2], [3]).children.length === 3})
|
test(function() {return m("div", [1], [2], [3]).children.length === 3})
|
||||||
|
|
||||||
//m.module
|
//m.module
|
||||||
|
test(function() {
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
var whatever = 1
|
||||||
|
var app = {
|
||||||
|
view: function() {
|
||||||
|
return [
|
||||||
|
whatever % 2 ? m('span', '% 2') : undefined,
|
||||||
|
m('div', 'bugs'),
|
||||||
|
m('a'),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.module(root, app)
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
whatever++
|
||||||
|
m.redraw()
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
whatever++
|
||||||
|
m.redraw()
|
||||||
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
return root.childNodes.length
|
||||||
|
})
|
||||||
|
|
||||||
test(function() {
|
test(function() {
|
||||||
mock.requestAnimationFrame.$resolve()
|
mock.requestAnimationFrame.$resolve()
|
||||||
|
|
||||||
|
|
@ -983,7 +1009,7 @@ function testMithril(mock) {
|
||||||
test(function() {
|
test(function() {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
m.render(root, m("div", [undefined]))
|
m.render(root, m("div", [undefined]))
|
||||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
return root.childNodes[0].childNodes.length === 0
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
|
|
@ -1006,19 +1032,19 @@ function testMithril(mock) {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
m.render(root, m("ul", [m("li")]))
|
m.render(root, m("ul", [m("li")]))
|
||||||
m.render(root, m("ul", [m("li"), undefined]))
|
m.render(root, m("ul", [m("li"), undefined]))
|
||||||
return root.childNodes[0].childNodes[1].nodeValue === ""
|
return root.childNodes[0].childNodes.length == 1
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
m.render(root, m("ul", [m("li"), m("li")]))
|
m.render(root, m("ul", [m("li"), m("li")]))
|
||||||
m.render(root, m("ul", [m("li"), undefined]))
|
m.render(root, m("ul", [m("li"), undefined]))
|
||||||
return root.childNodes[0].childNodes.length == 2 && root.childNodes[0].childNodes[1].nodeValue === ""
|
return root.childNodes[0].childNodes.length == 1
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
m.render(root, m("ul", [m("li")]))
|
m.render(root, m("ul", [m("li")]))
|
||||||
m.render(root, m("ul", [undefined]))
|
m.render(root, m("ul", [undefined]))
|
||||||
return root.childNodes[0].childNodes[0].nodeValue === ""
|
return root.childNodes[0].childNodes.length == 0
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
|
|
@ -1201,18 +1227,18 @@ function testMithril(mock) {
|
||||||
m.render(root, m("div", [m("button"), m("ul")]))
|
m.render(root, m("div", [m("button"), m("ul")]))
|
||||||
var valueBefore = root.childNodes[0].childNodes[0].nodeName
|
var valueBefore = root.childNodes[0].childNodes[0].nodeName
|
||||||
m.render(root, m("div", [undefined, m("ul")]))
|
m.render(root, m("div", [undefined, m("ul")]))
|
||||||
var valueAfter = root.childNodes[0].childNodes[0].nodeValue
|
var valueAfter = root.childNodes[0].childNodes[0].nodeName
|
||||||
return valueBefore === "BUTTON" && valueAfter === ""
|
return valueBefore === "BUTTON" && valueAfter === "UL"
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
var root = mock.document.createElement("div")
|
var root = mock.document.createElement("div")
|
||||||
m.render(root, m("div", [m("ul"), undefined]))
|
m.render(root, m("div", [m("ul"), undefined]))
|
||||||
var valueBefore1 = root.childNodes[0].childNodes[0].nodeName
|
var valueBefore1 = root.childNodes[0].childNodes[0].nodeName
|
||||||
var valueBefore2 = root.childNodes[0].childNodes[1].nodeValue
|
var valueBefore2 = root.childNodes[0].childNodes.length
|
||||||
m.render(root, m("div", [undefined, m("ul")]))
|
m.render(root, m("div", [undefined, m("ul")]))
|
||||||
var valueAfter1 = root.childNodes[0].childNodes[0].nodeValue
|
var valueAfter1 = root.childNodes[0].childNodes[0].nodeName
|
||||||
var valueAfter2 = root.childNodes[0].childNodes[1].nodeName
|
var valueAfter2 = root.childNodes[0].childNodes.length
|
||||||
return valueBefore1 === "UL" && valueAfter1 === "" && valueBefore2 === "" && valueAfter2 === "UL"
|
return valueBefore1 === "UL" && valueAfter1 === "UL" && valueBefore2 === 1 && valueAfter2 === 1
|
||||||
})
|
})
|
||||||
test(function() {
|
test(function() {
|
||||||
//https://github.com/lhorie/mithril.js/issues/79
|
//https://github.com/lhorie/mithril.js/issues/79
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue