Skip to content

Commit

Permalink
Merge pull request #50 from canjs/fix-late-registration
Browse files Browse the repository at this point in the history
making sure to actually set __CANJS_DEVTOOLS__ global
  • Loading branch information
phillipskevin committed Jun 22, 2018
2 parents 8201a6d + 62f0d62 commit af9a923
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
26 changes: 15 additions & 11 deletions can-debug-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if availab
testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if __CANJS_DEVTOOLS__ is set later", function(assert) {
var done = assert.async();
var fakeWindow = {};
var fakeDevtoolsGlobal = {
register: function(can) {
assert.ok("Symbol" in can, "can.Symbol passed");
assert.ok("Reflect" in can, "can.Reflect passed");
assert.ok("queues" in can, "can.queues passed");
assert.ok("getGraph" in can, "can.getGraph passed");
assert.ok("formatGraph" in can, "can.formatGraph passed");
assert.ok("mergeDeep" in can, "can.mergeDeep passed");

assert.equal(fakeWindow.__CANJS_DEVTOOLS__, fakeDevtoolsGlobal, "sets window.__CANJS_DEVTOOLS__");

done();
}
};

clone({
"can-globals": {
Expand All @@ -89,16 +103,6 @@ testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if __CANJS
})
.import("can-debug")
.then(function() {
fakeWindow.__CANJS_DEVTOOLS__ = {
register: function(can) {
assert.ok("Symbol" in can, "can.Symbol passed");
assert.ok("Reflect" in can, "can.Reflect passed");
assert.ok("queues" in can, "can.queues passed");
assert.ok("getGraph" in can, "can.getGraph passed");
assert.ok("formatGraph" in can, "can.formatGraph passed");
assert.ok("mergeDeep" in can, "can.mergeDeep passed");
done();
}
};
fakeWindow.__CANJS_DEVTOOLS__ = fakeDevtoolsGlobal;
});
});
15 changes: 10 additions & 5 deletions can-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ var devtoolsCanModules = {
formatGraph: namespace.debug.formatGraph,
mergeDeep: mergeDeep
};
var devtoolsGlobalName = "__CANJS_DEVTOOLS__";

if (global.__CANJS_DEVTOOLS__) {
global.__CANJS_DEVTOOLS__.register(devtoolsCanModules);
if (global[devtoolsGlobalName]) {
global[devtoolsGlobalName].register(devtoolsCanModules);
} else {
Object.defineProperty(global, "__CANJS_DEVTOOLS__", {
Object.defineProperty(global, devtoolsGlobalName, {
set: function(devtoolsGlobal) {
Object.defineProperty(global, devtoolsGlobalName, {
value: devtoolsGlobal
});

devtoolsGlobal.register(devtoolsCanModules);
return devtoolsGlobal;
}
},
configurable: true
});
}

0 comments on commit af9a923

Please sign in to comment.