Skip to content

Commit 8b8abde

Browse files
committed
Release Artifacts for v2.2.14
[skip ci]
1 parent 2f56c8e commit 8b8abde

File tree

6 files changed

+73
-88
lines changed

6 files changed

+73
-88
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
## What is Mithril.js?
1717

18-
A modern client-side JavaScript framework for building Single Page Applications. It's small (<!-- size -->9.01 KB<!-- /size --> gzipped), fast and provides routing and XHR utilities out of the box.
18+
A modern client-side JavaScript framework for building Single Page Applications. It's small (<!-- size -->8.96 KB<!-- /size --> gzipped), fast and provides routing and XHR utilities out of the box.
1919

2020
Mithril.js is used by companies like Vimeo and Nike, and open source platforms like Lichess 👍.
2121

Diff for: docs/recent-changes.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11

2+
# Release v2.2.14
3+
4+
### Patch Changes
5+
6+
#### [Improve handling of is-elements and Fix tiny bugs of setAttr()/updateStyle() (@kfule)](https://github.com/MithrilJS/mithril.js/pull/2988)
7+
8+
Fixes a few tiny bugs in attributes and style properties updates, and improves handling of is-elements in updateNode().
9+
#### [domFor: always get generation from delayedRemoval instead of parameter (@kfule)](https://github.com/MithrilJS/mithril.js/pull/3007)
10+
11+
The `generation` of domFor is no longer passed as a parameter. This allows domFor to work well in onbeforeremove and onremove and reduces the amount of code.
12+
#### [render: wrap stateResult and attrsResult in Promise.resolve(), fix #2592 (@kfule)](https://github.com/MithrilJS/mithril.js/pull/3005)
13+
14+
This PR wraps the return value of onbeforeremove in Promise.resolve(). This ensures that thenable objects are also always processed asynchronously. fix #2592.
15+
216
# Release v2.2.13
317

418
### Patch Changes

Diff for: mithril.js

+54-83
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;(function() {
22
"use strict"
33
function Vnode(tag, key, attrs0, children, text, dom) {
4-
return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: undefined, events: undefined, instance: undefined}
4+
return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, is: undefined, domSize: undefined, state: undefined, events: undefined, instance: undefined}
55
}
66
Vnode.normalize = function(node) {
77
if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
@@ -128,6 +128,8 @@ function execSelector(state, vnode) {
128128
if (state.tag === "input" && hasOwn.call(attrs, "type")) {
129129
attrs = Object.assign({type: attrs.type}, attrs)
130130
}
131+
// This reduces the complexity of the evaluation of "is" within the render function.
132+
vnode.is = attrs.is
131133
vnode.attrs = attrs
132134
return vnode
133135
}
@@ -154,12 +156,12 @@ hyperscript.fragment = function() {
154156
return vnode2
155157
}
156158
var delayedRemoval0 = new WeakMap
157-
function *domFor1(vnode4, object = {}) {
159+
function *domFor1(vnode4) {
158160
// To avoid unintended mangling of the internal bundler,
159161
// parameter destructuring is0 not used here.
160162
var dom = vnode4.dom
161163
var domSize0 = vnode4.domSize
162-
var generation0 = object.generation
164+
var generation0 = delayedRemoval0.get(dom)
163165
if (dom != null) do {
164166
var nextSibling = dom.nextSibling
165167
if (delayedRemoval0.get(dom) === generation0) {
@@ -279,7 +281,7 @@ var _11 = function() {
279281
function createElement(parent, vnode3, hooks, ns, nextSibling) {
280282
var tag = vnode3.tag
281283
var attrs2 = vnode3.attrs
282-
var is = attrs2 && attrs2.is
284+
var is = vnode3.is
283285
ns = getNameSpace(vnode3) || ns
284286
var element = ns ?
285287
is ? getDocument(parent).createElementNS(ns, tag, {is: is}) : getDocument(parent).createElementNS(ns, tag) :
@@ -549,7 +551,7 @@ var _11 = function() {
549551
}
550552
function updateNode(parent, old, vnode3, hooks, nextSibling, ns) {
551553
var oldTag = old.tag, tag = vnode3.tag
552-
if (oldTag === tag) {
554+
if (oldTag === tag && old.is === vnode3.is) {
553555
vnode3.state = old.state
554556
vnode3.events = old.events
555557
if (shouldNotUpdate(vnode3, old)) return
@@ -579,7 +581,7 @@ var _11 = function() {
579581
}
580582
function updateHTML(parent, old, vnode3, ns, nextSibling) {
581583
if (old.children !== vnode3.children) {
582-
removeDOM(parent, old, undefined)
584+
removeDOM(parent, old)
583585
createHTML(parent, vnode3, ns, nextSibling)
584586
}
585587
else {
@@ -732,71 +734,36 @@ var _11 = function() {
732734
if (vnode3 != null) removeNode(parent, vnode3)
733735
}
734736
}
735-
function removeNode(parent, vnode3) {
736-
var mask = 0
737+
function tryBlockRemove(parent, vnode3, source, counter) {
737738
var original = vnode3.state
738-
var stateResult, attrsResult
739-
if (typeof vnode3.tag !== "string" && typeof vnode3.state.onbeforeremove === "function") {
740-
var result = callHook.call(vnode3.state.onbeforeremove, vnode3)
741-
if (result != null && typeof result.then === "function") {
742-
mask = 1
743-
stateResult = result
744-
}
745-
}
746-
if (vnode3.attrs && typeof vnode3.attrs.onbeforeremove === "function") {
747-
var result = callHook.call(vnode3.attrs.onbeforeremove, vnode3)
748-
if (result != null && typeof result.then === "function") {
749-
// eslint-disable-next-line no-bitwise
750-
mask |= 2
751-
attrsResult = result
752-
}
753-
}
754-
checkState(vnode3, original)
755-
var generation
756-
// If we can, try to fast-path it and avoid all the overhead of awaiting
757-
if (!mask) {
739+
var result = callHook.call(source.onbeforeremove, vnode3)
740+
if (result == null) return
741+
var generation = currentRender
742+
for (var dom of domFor0(vnode3)) delayedRemoval.set(dom, generation)
743+
counter.v++
744+
Promise.resolve(result).finally(function () {
745+
checkState(vnode3, original)
746+
tryResumeRemove(parent, vnode3, counter)
747+
})
748+
}
749+
function tryResumeRemove(parent, vnode3, counter) {
750+
if (--counter.v === 0) {
758751
onremove(vnode3)
759-
removeDOM(parent, vnode3, generation)
760-
} else {
761-
generation = currentRender
762-
for (var dom of domFor0(vnode3)) delayedRemoval.set(dom, generation)
763-
if (stateResult != null) {
764-
stateResult.finally(function () {
765-
// eslint-disable-next-line no-bitwise
766-
if (mask & 1) {
767-
// eslint-disable-next-line no-bitwise
768-
mask &= 2
769-
if (!mask) {
770-
checkState(vnode3, original)
771-
onremove(vnode3)
772-
removeDOM(parent, vnode3, generation)
773-
}
774-
}
775-
})
776-
}
777-
if (attrsResult != null) {
778-
attrsResult.finally(function () {
779-
// eslint-disable-next-line no-bitwise
780-
if (mask & 2) {
781-
// eslint-disable-next-line no-bitwise
782-
mask &= 1
783-
if (!mask) {
784-
checkState(vnode3, original)
785-
onremove(vnode3)
786-
removeDOM(parent, vnode3, generation)
787-
}
788-
}
789-
})
790-
}
752+
removeDOM(parent, vnode3)
791753
}
792754
}
793-
function removeDOM(parent, vnode3, generation) {
755+
function removeNode(parent, vnode3) {
756+
var counter = {v: 1}
757+
if (typeof vnode3.tag !== "string" && typeof vnode3.state.onbeforeremove === "function") tryBlockRemove(parent, vnode3, vnode3.state, counter)
758+
if (vnode3.attrs && typeof vnode3.attrs.onbeforeremove === "function") tryBlockRemove(parent, vnode3, vnode3.attrs, counter)
759+
tryResumeRemove(parent, vnode3, counter)
760+
}
761+
function removeDOM(parent, vnode3) {
794762
if (vnode3.dom == null) return
795763
if (vnode3.domSize == null) {
796-
// don't allocate for the common case
797-
if (delayedRemoval.get(vnode3.dom) === generation) parent.removeChild(vnode3.dom)
764+
parent.removeChild(vnode3.dom)
798765
} else {
799-
for (var dom of domFor0(vnode3, {generation})) parent.removeChild(dom)
766+
for (var dom of domFor0(vnode3)) parent.removeChild(dom)
800767
}
801768
}
802769
function onremove(vnode3) {
@@ -821,7 +788,7 @@ var _11 = function() {
821788
}
822789
}
823790
function setAttr(vnode3, key, old, value, ns) {
824-
if (key === "key" || key === "is" || value == null || isLifecycleMethod(key) || (old === value && !isFormAttribute(vnode3, key)) && typeof value !== "object") return
791+
if (key === "key" || value == null || isLifecycleMethod(key) || (old === value && !isFormAttribute(vnode3, key)) && typeof value !== "object") return
825792
if (key[0] === "o" && key[1] === "n") return updateEvent(vnode3, key, value)
826793
if (key.slice(0, 6) === "xlink:") vnode3.dom.setAttributeNS("http://www.w3.org/1999/xlink", key.slice(6), value)
827794
else if (key === "style") updateStyle(vnode3.dom, old, value)
@@ -854,7 +821,7 @@ var _11 = function() {
854821
}
855822
}
856823
function removeAttr(vnode3, key, old, ns) {
857-
if (key === "key" || key === "is" || old == null || isLifecycleMethod(key)) return
824+
if (key === "key" || old == null || isLifecycleMethod(key)) return
858825
if (key[0] === "o" && key[1] === "n") updateEvent(vnode3, key, undefined)
859826
else if (key === "style") updateStyle(vnode3.dom, old, null)
860827
else if (
@@ -888,22 +855,24 @@ var _11 = function() {
888855
if ("selectedIndex" in attrs2) setAttr(vnode3, "selectedIndex", null, attrs2.selectedIndex, undefined)
889856
}
890857
function updateAttrs(vnode3, old, attrs2, ns) {
891-
if (old && old === attrs2) {
892-
console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major")
893-
}
894-
if (attrs2 != null) {
895-
for (var key in attrs2) {
896-
setAttr(vnode3, key, old && old[key], attrs2[key], ns)
897-
}
898-
}
858+
// Some attributes may NOT be case-sensitive (e.g. data-***),
859+
// so removal should be done first to prevent accidental removal for newly setting values.
899860
var val
900861
if (old != null) {
862+
if (old === attrs2) {
863+
console.warn("Don't reuse attrs object, use new object for every redraw, this will throw in next major")
864+
}
901865
for (var key in old) {
902866
if (((val = old[key]) != null) && (attrs2 == null || attrs2[key] == null)) {
903867
removeAttr(vnode3, key, val, ns)
904868
}
905869
}
906870
}
871+
if (attrs2 != null) {
872+
for (var key in attrs2) {
873+
setAttr(vnode3, key, old && old[key], attrs2[key], ns)
874+
}
875+
}
907876
}
908877
function isFormAttribute(vnode3, attr) {
909878
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" && vnode3.dom === activeElement(vnode3.dom) || vnode3.tag === "option" && vnode3.dom.parentNode === activeElement(vnode3.dom)
@@ -915,7 +884,7 @@ var _11 = function() {
915884
// Filter out namespaced keys
916885
return ns === undefined && (
917886
// If it's a custom element, just keep it.
918-
vnode3.tag.indexOf("-") > -1 || vnode3.attrs != null && vnode3.attrs.is ||
887+
vnode3.tag.indexOf("-") > -1 || vnode3.is ||
919888
// If it's a normal element, let's try to avoid a few browser bugs.
920889
key !== "href" && key !== "list" && key !== "form" && key !== "width" && key !== "height"// && key !== "type"
921890
// Defer the property check until *after* we check everything.
@@ -933,7 +902,7 @@ var _11 = function() {
933902
element.style = style
934903
} else if (old == null || typeof old !== "object") {
935904
// `old` is missing or a string, `style` is an object.
936-
element.style.cssText = ""
905+
element.style = ""
937906
// Add new style properties
938907
for (var key in style) {
939908
var value = style[key]
@@ -944,6 +913,15 @@ var _11 = function() {
944913
}
945914
} else {
946915
// Both old & new are (different) objects.
916+
// Remove style properties that no longer exist
917+
// Style properties may have two cases(dash-case and camelCase),
918+
// so removal should be done first to prevent accidental removal for newly setting values.
919+
for (var key in old) {
920+
if (old[key] != null && style[key] == null) {
921+
if (key.includes("-")) element.style.removeProperty(key)
922+
else element.style[key] = ""
923+
}
924+
}
947925
// Update style properties that have changed
948926
for (var key in style) {
949927
var value = style[key]
@@ -952,13 +930,6 @@ var _11 = function() {
952930
else element.style[key] = value
953931
}
954932
}
955-
// Remove style properties that no longer exist
956-
for (var key in old) {
957-
if (old[key] != null && style[key] == null) {
958-
if (key.includes("-")) element.style.removeProperty(key)
959-
else element.style[key] = ""
960-
}
961-
}
962933
}
963934
}
964935
// Here's an explanation of how this works:

Diff for: mithril.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mithril",
3-
"version": "2.2.13",
3+
"version": "2.2.14",
44
"description": "A framework for building brilliant applications",
55
"author": "Leo Horie",
66
"license": "MIT",

0 commit comments

Comments
 (0)