add ability to abort from controller::onunload
This commit is contained in:
parent
81f3367be9
commit
b486e53b4b
3 changed files with 31 additions and 7 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
[v0.1.16](/mithril/archive/v0.1.6) - maintenance
|
||||
|
||||
### News:
|
||||
|
||||
- controller::onunload now receives an event parameter so that the unloading can be aborted [#135](https://github.com/lhorie/mithril.js/issues/135)
|
||||
|
||||
### Bug Fixes:
|
||||
|
||||
- prevent route change when only hash changes in non-hash mode [#107](https://github.com/lhorie/mithril.js/issues/107)
|
||||
|
|
|
|||
|
|
@ -129,6 +129,17 @@ m.module(document, module2); // logs "unloading module 1"
|
|||
|
||||
This mechanism is useful to clear timers and unsubscribe event handlers. If you have a hierarchy of components, you can recursively call `onunload` on all the components in the tree or use a [pubsub](http://microjs.com/#pubsub) library to unload specific components on demand.
|
||||
|
||||
You can also use this event to prevent a module from being unloaded (e.g. to alert a user to save their changes before navigating away from a page)
|
||||
|
||||
```javascript
|
||||
var module1 = {}
|
||||
module1.controller = function() {
|
||||
this.onunload = function(e) {
|
||||
if (!confirm("are you sure you want to leave this page?")) e.preventDefault()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Signature
|
||||
|
|
@ -140,7 +151,8 @@ void module(DOMElement rootElement, Module module)
|
|||
|
||||
where:
|
||||
Module :: Object { Controller, void view(Object controllerInstance) }
|
||||
Controller :: void controller() | void controller() { prototype: void unload() }
|
||||
Controller :: void controller() | void controller() { prototype: void unload(UnloadEvent e) }
|
||||
UnloadEvent :: Object {void preventDefault()}
|
||||
```
|
||||
|
||||
- **DOMElement rootElement**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue