jquery-atomic-nav
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -14,2 +14,3 @@ (typeof module !== "undefined" && module !== null ? function(moduleBody) { | ||
this._isDestroyed = false; | ||
this.whenDestroyed = new $.Deferred(); | ||
} | ||
@@ -29,2 +30,3 @@ | ||
this._isDestroyed = true; | ||
this.whenDestroyed.resolve(); | ||
return $(this).trigger('destroyed'); | ||
@@ -31,0 +33,0 @@ }; |
{ | ||
"name": "jquery-atomic-nav", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"main": "dist/jquery-atomic-nav.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -8,2 +8,10 @@ # jquery-atomic-nav | ||
## Usage | ||
Routes are defined via `when` method. Each route body is executed when a navigation state is entered. The navigation state can be used to define nested routes, and to track when the user leaves that navigation state. The library defines the "root" navigation state that is always active - that is the starting place where routes are registered. | ||
To detect when a navigation state is no longer active, register a callback on the state object using the `whenDestroyed.then` method. The `whenDestroyed` property is a full-fledged promise object, so the callback will be called even when trying to register *after* the user left the navigation state. This is helpful to easily clean up UI created as a result of an asynchronous operation: the operation may complete after the navigation state has become inactive, so attaching a simple event listener would miss out on the cleanup. | ||
## Examples | ||
For more examples see `/example/index.html`. | ||
@@ -21,3 +29,3 @@ | ||
$(fooNav).on('destroyed', function() { | ||
fooNav.whenDestroyed.then(function() { | ||
console.log('left "foo" state'); | ||
@@ -33,3 +41,3 @@ | ||
$(barNav).on('destroyed', function() { | ||
barNav.whenDestroyed.then(function() { | ||
console.log('left "foo/bar" state'); | ||
@@ -45,3 +53,3 @@ | ||
$(bazNav).on('destroyed', function() { | ||
bazNav.whenDestroyed.then(function() { | ||
console.log('left "baz" state with "' + someParam + '"'); | ||
@@ -48,0 +56,0 @@ }); |
Sorry, the diff of this file is not supported yet
15005
170
79