Skip to content

Commit a4d2ef1

Browse files
committed
Release Artifacts for v2.3.2
[skip ci]
1 parent be09e8a commit a4d2ef1

File tree

6 files changed

+33
-48
lines changed

6 files changed

+33
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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.00 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.92 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

docs/recent-changes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
# Release v2.3.2
3+
4+
### Patch Changes
5+
6+
#### [Refactor router, fixes #2505 and #2778 (@kfule)](https://github.com/MithrilJS/mithril.js/pull/3027)
7+
8+
This PR refactors the router code to fix two issues (#2505 and #2778).
9+
210
# Release v2.3.1
311

412
### Patch Changes

mithril.js

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,6 @@ var censor = function(attrs4, extras) {
14711471
}
14721472
return result2
14731473
}
1474-
var sentinel0 = {}
14751474
function decodeURIComponentSave(component) {
14761475
try {
14771476
return decodeURIComponent(component)
@@ -1486,24 +1485,16 @@ var _26 = function($window, mountRedraw00) {
14861485
: typeof $window.setImmediate === "function" ? $window.setImmediate : $window.setTimeout
14871486
var p = Promise.resolve()
14881487
var scheduled = false
1489-
// state === 0: init
1490-
// state === 1: scheduled
1491-
// state === 2: done
14921488
var ready = false
1493-
var state = 0
1489+
var hasBeenResolved = false
14941490
var compiled, fallbackRoute
1495-
var currentResolver = sentinel0, component, attrs3, currentPath, lastUpdate
1491+
var currentResolver, component, attrs3, currentPath, lastUpdate
14961492
var RouterRoot = {
1497-
onbeforeupdate: function() {
1498-
state = state ? 2 : 1
1499-
return !(!state || sentinel0 === currentResolver)
1500-
},
15011493
onremove: function() {
15021494
$window.removeEventListener("popstate", fireAsync, false)
1503-
$window.removeEventListener("hashchange", resolveRoute, false)
15041495
},
15051496
view: function() {
1506-
if (!state || sentinel0 === currentResolver) return
1497+
if (!hasBeenResolved) return
15071498
// Wrap in a fragment0 to preserve existing key3 semantics
15081499
var vnode6 = [Vnode(component, attrs3.key, attrs3)]
15091500
if (currentResolver) vnode6 = currentResolver.render(vnode6[0])
@@ -1533,13 +1524,10 @@ var _26 = function($window, mountRedraw00) {
15331524
Object.assign(data.params, $window.history.state)
15341525
function reject(e) {
15351526
console.error(e)
1536-
setPath(fallbackRoute, null, {replace: true})
1527+
route.set(fallbackRoute, null, {replace: true})
15371528
}
15381529
loop(0)
15391530
function loop(i) {
1540-
// state === 0: init
1541-
// state === 1: scheduled
1542-
// state === 2: done
15431531
for (; i < compiled.length; i++) {
15441532
if (compiled[i].check(data)) {
15451533
var payload = compiled[i].component
@@ -1551,9 +1539,9 @@ var _26 = function($window, mountRedraw00) {
15511539
component = comp != null && (typeof comp.view === "function" || typeof comp === "function")? comp : "div"
15521540
attrs3 = data.params, currentPath = path0, lastUpdate = null
15531541
currentResolver = payload.render ? payload : null
1554-
if (state === 2) mountRedraw00.redraw()
1542+
if (hasBeenResolved) mountRedraw00.redraw()
15551543
else {
1556-
state = 2
1544+
hasBeenResolved = true
15571545
mountRedraw00.redraw.sync()
15581546
}
15591547
}
@@ -1568,20 +1556,16 @@ var _26 = function($window, mountRedraw00) {
15681556
return payload.onmatch(data.params, path0, matchedRoute)
15691557
}).then(update, path0 === fallbackRoute ? null : reject)
15701558
}
1571-
else update("div")
1559+
else update(/* "div" */)
15721560
return
15731561
}
15741562
}
15751563
if (path0 === fallbackRoute) {
15761564
throw new Error("Could not resolve default route " + fallbackRoute + ".")
15771565
}
1578-
setPath(fallbackRoute, null, {replace: true})
1566+
route.set(fallbackRoute, null, {replace: true})
15791567
}
15801568
}
1581-
// Set it unconditionally so `m4.route.set` and `m4.route.Link` both work,
1582-
// even if neither `pushState` nor `hashchange` are supported. It's
1583-
// cleared if `hashchange` is2 used, since that makes it automatically
1584-
// async.
15851569
function fireAsync() {
15861570
if (!scheduled) {
15871571
scheduled = true
@@ -1591,19 +1575,6 @@ var _26 = function($window, mountRedraw00) {
15911575
callAsync(resolveRoute)
15921576
}
15931577
}
1594-
function setPath(path0, data, options) {
1595-
path0 = buildPathname(path0, data)
1596-
if (ready) {
1597-
fireAsync()
1598-
var state = options ? options.state : null
1599-
var title = options ? options.title : null
1600-
if (options && options.replace) $window.history.replaceState(state, title, route.prefix + path0)
1601-
else $window.history.pushState(state, title, route.prefix + path0)
1602-
}
1603-
else {
1604-
$window.location.href = route.prefix + path0
1605-
}
1606-
}
16071578
function route(root, defaultRoute, routes) {
16081579
if (!root) throw new TypeError("DOM element being rendered to does not exist.")
16091580
compiled = Object.keys(routes).map(function(route) {
@@ -1624,11 +1595,7 @@ var _26 = function($window, mountRedraw00) {
16241595
throw new ReferenceError("Default route doesn't match any known routes.")
16251596
}
16261597
}
1627-
if (typeof $window.history.pushState === "function") {
1628-
$window.addEventListener("popstate", fireAsync, false)
1629-
} else if (route.prefix[0] === "#") {
1630-
$window.addEventListener("hashchange", resolveRoute, false)
1631-
}
1598+
$window.addEventListener("popstate", fireAsync, false)
16321599
ready = true
16331600
mountRedraw00.mount(root, RouterRoot)
16341601
resolveRoute()
@@ -1639,7 +1606,17 @@ var _26 = function($window, mountRedraw00) {
16391606
options.replace = true
16401607
}
16411608
lastUpdate = null
1642-
setPath(path0, data, options)
1609+
path0 = buildPathname(path0, data)
1610+
if (ready) {
1611+
fireAsync()
1612+
var state = options ? options.state : null
1613+
var title = options ? options.title : null
1614+
if (options && options.replace) $window.history.replaceState(state, title, route.prefix + path0)
1615+
else $window.history.pushState(state, title, route.prefix + path0)
1616+
}
1617+
else {
1618+
$window.location.href = route.prefix + path0
1619+
}
16431620
}
16441621
route.get = function() {return currentPath}
16451622
route.prefix = "#!"

mithril.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mithril",
3-
"version": "2.3.1",
3+
"version": "2.3.2",
44
"description": "A framework for building brilliant applications",
55
"author": "Leo Horie",
66
"license": "MIT",

0 commit comments

Comments
 (0)