Skip to content

Commit

Permalink
Call ObservationRecorder.add when observable is read
Browse files Browse the repository at this point in the history
Closes #91
  • Loading branch information
m-mujica committed Feb 23, 2018
1 parent dbe88dc commit ee617ae
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
6 changes: 5 additions & 1 deletion can-route-pushstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var KeyTree = require("can-key-tree");

var queues = require("can-queues");
var SimpleObservable = require("can-simple-observable");
var ObservationRecorder = require("can-observation-recorder");

var isNode = require('can-globals/is-node/is-node');
var LOCATION = require('can-globals/location/location');
Expand Down Expand Up @@ -231,7 +232,10 @@ canReflect.assign(PushstateObservable.prototype,{

domEvents.removeEventListener(window, 'popstate', this.dispatchHandlers);
},
get: getCurrentUrl,
get: function get() {
ObservationRecorder.add(this);
return getCurrentUrl();
},
set: function(path){
var newProps = route.deparam(path);
var oldProps = route.deparam(getCurrentUrl());
Expand Down
20 changes: 20 additions & 0 deletions can-route-pushstate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,26 @@ function makeTest(mapModuleName){

});

test("currentRule should signal when it is read", function(assert) {
var done = assert.async();

makeTestingIframe(function(info, cleanup) {
info.history.pushState(null, null, "/");

info.route.register("");
info.route.register("{page}", { foo: "baz" });
info.route.start()

info.window.ObservationRecorder.start();
info.history.pushState(null, null, "home");
var deps = info.window.ObservationRecorder.stop();

ok(deps.valueDependencies.has(info.route.bindings.pushstate));
cleanup();
done();
});
});

test("sticky enough routes", function () {
stop();
makeTestingIframe(function (info, done) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"can-dom-events": "^1.1.0",
"can-globals": "<2.0.0",
"can-key-tree": "<2.0.0",
"can-observation-recorder": "^1.0.2",
"can-queues": "<2.0.0",
"can-reflect": "^1.8.0",
"can-route": "^4.0.0",
Expand Down
19 changes: 13 additions & 6 deletions test/testing.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@
<script>
steal.done().then(function() {
Promise.all([
System.import('can-route-pushstate'),
System.import("can-route-pushstate"),
System.import(window.parent.MAP_MODULE_NAME),
System.import('can-queues')
]).then(function(modules){
System.import("can-queues"),
System.import("can-observation-recorder")
]).then(function(modules) {
window.route = modules[0];
window.CanMap = modules[1];
window.queues = modules[2];
setTimeout(function () {
window.parent.routeTestReady && window.parent.routeTestReady(route, window.location, window.history, window)
window.ObservationRecorder = modules[3];
setTimeout(function() {
window.parent.routeTestReady &&
window.parent.routeTestReady(
route,
window.location,
window.history,
window
);
}, 30);
});
});
</script>

</body>
</html>

0 comments on commit ee617ae

Please sign in to comment.