From bc5a972cb0e1d0d8f81874f26f2a2622250f5c03 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Thu, 1 Dec 2016 02:30:43 -0500 Subject: [PATCH] add note about unmount prevention --- docs/v1.x-migration.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/v1.x-migration.md b/docs/v1.x-migration.md index 6f4a415c..931f7689 100644 --- a/docs/v1.x-migration.md +++ b/docs/v1.x-migration.md @@ -15,6 +15,7 @@ - [`m.route` and anchor tags](#mroute-and-anchor-tags) - [Reading/writing the current route](#readingwriting-the-current-route) - [Accessing route params](#accessing-route-params) +- [Preventing unmounting](#preventing-unmounting) - [`m.request`](#mrequest) - [`xlink` namespace required](#xlink-namespace-required) - [Nested arrays in views](#nested-arrays-in-views) @@ -408,6 +409,37 @@ m.route(document.body, "/booga", { --- +## Preventing unmounting + +It is no longer possible to prevent unmounting via `onunload`'s `e.preventDefault()`. Instead you should explicitly call `m.route.set` when the expected conditions are met. + +### `v0.2.x` + +```javascript +var Component = { + controller: function() { + this.onunload = function(e) { + if (condition) e.preventDefault() + } + }, + view: function() { + return m("a[href=/]", {config: m.route}) + } +} +``` + +### `v1.x` + +```javascript +var Component = { + view: function() { + return m("a", {onclick: function() {if (!condition) m.route.set("/")}}) + } +} +``` + +--- + ## m.request Promises returned by [m.request](request.md) are no longer `m.prop` getter-setters. In addition, `initialValue` is no longer a supported option.