elm-hot
Advanced tools
Comparing version 1.1.3 to 1.1.4
{ | ||
"name": "elm-hot", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Hot code swapping for Elm", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -16,2 +16,9 @@ [![CircleCI](https://circleci.com/gh/klazuka/elm-hot.svg?style=svg)](https://circleci.com/gh/klazuka/elm-hot) | ||
### 1.1.4 | ||
- fixed a bug where HMR failed because `Browser.Navigation.Key` changed location | ||
- fixed a crash when the app's `Model` contains `Json.Encode.null` | ||
### 1.1.3 | ||
- fixed a crash when using Elm debugger and elm/browser 1.0.2 | ||
### 1.1.2 | ||
@@ -18,0 +25,0 @@ - fixed a bug where HMR would not work for very small ("toy") Elm projects |
@@ -155,3 +155,2 @@ //////////////////// HMR BEGIN //////////////////// | ||
portSends: portSends, | ||
navKeyPath: null, // array of JS property names by which the Browser.Navigation.Key can be found in the model | ||
lastState: null // last Elm app state (root model) | ||
@@ -360,3 +359,3 @@ }; | ||
if (typeof item.value === "undefined") { | ||
if (typeof item.value === "undefined" || item.value === null) { | ||
continue; | ||
@@ -419,2 +418,4 @@ } | ||
if (typeof elmSymbol("elm$browser$Browser$application") !== 'undefined') { | ||
var oldKeyLoc = findNavKey(oldModel); | ||
// attempt to find the Browser.Navigation.Key in the newly-constructed model | ||
@@ -426,20 +427,15 @@ // and bring it along with the rest of the old data. | ||
error = "could not find Browser.Navigation.Key in the new app model"; | ||
} else if (instance.navKeyPath === null) { | ||
} else if (oldKeyLoc === null) { | ||
error = "could not find Browser.Navigation.Key in the old app model."; | ||
} else if (newKeyLoc.keypath.toString() !== instance.navKeyPath.toString()) { | ||
} else if (newKeyLoc.keypath.toString() !== oldKeyLoc.keypath.toString()) { | ||
error = "the location of the Browser.Navigation.Key in the model has changed."; | ||
} else { | ||
var oldNavKey = getAt(instance.navKeyPath, oldModel); | ||
if (oldNavKey === null) { | ||
error = "keypath " + instance.navKeyPath + " is invalid. Please report a bug." | ||
} else { | ||
// remove event listeners attached to the old nav key | ||
removeNavKeyListeners(oldNavKey); | ||
// remove event listeners attached to the old nav key | ||
removeNavKeyListeners(oldKeyLoc.value); | ||
// insert the new nav key into the old model in the exact same location | ||
var parentKeyPath = newKeyLoc.keypath.slice(0, -1); | ||
var lastSegment = newKeyLoc.keypath.slice(-1)[0]; | ||
var oldParent = getAt(parentKeyPath, oldModel); | ||
oldParent[lastSegment] = newKeyLoc.value; | ||
} | ||
// insert the new nav key into the old model in the exact same location | ||
var parentKeyPath = oldKeyLoc.keypath.slice(0, -1); | ||
var lastSegment = oldKeyLoc.keypath.slice(-1)[0]; | ||
var oldParent = getAt(parentKeyPath, oldModel); | ||
oldParent[lastSegment] = newKeyLoc.value; | ||
} | ||
@@ -461,14 +457,2 @@ | ||
initializingInstance.lastState = initialStateTuple.a; | ||
// capture Browser.application's navigation key for later | ||
if (typeof elmSymbol("elm$browser$Browser$application") !== 'undefined') { | ||
var navKeyLoc = findNavKey(initializingInstance.lastState); | ||
if (!navKeyLoc) { | ||
console.error("[elm-hot] Hot-swapping disabled for " + instance.path | ||
+ ": could not find Browser.Navigation.Key in your model."); | ||
instance.navKeyPath = null; | ||
} else { | ||
instance.navKeyPath = navKeyLoc.keypath; | ||
} | ||
} | ||
} | ||
@@ -475,0 +459,0 @@ |
@@ -12,6 +12,6 @@ { | ||
"elm/html": "1.0.0", | ||
"elm/json": "1.1.3", | ||
"elm/url": "1.0.0" | ||
}, | ||
"indirect": { | ||
"elm/json": "1.1.3", | ||
"elm/time": "1.0.0", | ||
@@ -25,2 +25,2 @@ "elm/virtual-dom": "1.0.2" | ||
} | ||
} | ||
} |
@@ -84,2 +84,7 @@ const path = require('path'); | ||
test('Browser.Navigation.Key can be found even when the keypath changes', async t => { | ||
// see https://github.com/klazuka/elm-hot/issues/35 | ||
await doBrowserApplicationTest(t, "BrowserApplicationNavKeyMoved"); | ||
}); | ||
test('init side effects do not run after HMR', async t => { | ||
@@ -169,2 +174,7 @@ // see https://github.com/klazuka/elm-hot-webpack-loader/issues/1 | ||
test('an Elm model containing `null` should not crash', async t => { | ||
// see https://github.com/klazuka/elm-hot/pull/36 | ||
await doCounterTest(t, "BrowserApplicationWithNull"); | ||
}); | ||
async function doCounterTest(t, testName) { | ||
@@ -171,0 +181,0 @@ const page = t.context.page; |
Sorry, the diff of this file is not supported yet
486627
90
89
867