Last active
December 17, 2015 04:58
-
-
Save belisarius222/5553897 to your computer and use it in GitHub Desktop.
a super-bare-bones implementation of a reactive window.location (include this somewhere on the client in a Meteor app)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Location = {}; | |
this.Location = Location; | |
Location.dep = new Deps.Dependency; | |
Location.state = window.history.state; | |
window.onpopstate = function(event){ | |
Location.state = event.state; | |
// note that popstate gets fired on initial page load in Webkit, | |
// but not in Firefox ... | |
Location.dep.changed(); | |
}; | |
Location.getState = function() { | |
var self = this; | |
self.dep.depend(); | |
// Return the state we store, not the built-in, just in case | |
// we decide to store extra data with the state later. | |
return self.state; | |
}; | |
Location.go = function( /* arguments */ ) { | |
var self = this; | |
window.history.go(arguments); | |
self.dep.changed(); | |
}; | |
Location.pushState = function( /* arguments */ ) { | |
var self = this; | |
window.history.pushState(arguments); | |
self.dep.changed(); | |
}; | |
Location.replaceState = function( /* arguments */ ) { | |
var self = this; | |
window.history.replaceState(arguments); | |
self.dep.changed(); | |
}; | |
Location.forward = function() { | |
var self = this; | |
window.history.forward(); | |
self.dep.changed(); | |
}; | |
Location.back = function() { | |
var self = this; | |
window.history.back(); | |
self.dep.changed(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment