@@ -1471,7 +1471,6 @@ var censor = function(attrs4, extras) {
14711471 }
14721472 return result2
14731473}
1474- var sentinel0 = { }
14751474function 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 = "#!"
0 commit comments