-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0252ee4
commit d73fe2f
Showing
31 changed files
with
1,888 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*can-debug@1.0.1#can-debug*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-namespace', | ||
'./src/proxy-namespace', | ||
'./src/temporarily-bind', | ||
'./src/get-graph/get-graph', | ||
'./src/draw-graph/format-graph', | ||
'./src/draw-graph/draw-graph', | ||
'./src/what-i-change/what-i-change', | ||
'./src/what-changes-me/what-changes-me', | ||
'./src/get-what-i-change/get-what-i-change', | ||
'./src/get-what-changes-me/get-what-changes-me' | ||
], function (require, exports, module) { | ||
var namespace = require('can-namespace'); | ||
var proxyNamespace = require('./src/proxy-namespace'); | ||
var temporarilyBind = require('./src/temporarily-bind'); | ||
var getGraph = require('./src/get-graph/get-graph'); | ||
var formatGraph = require('./src/draw-graph/format-graph'); | ||
var drawGraph = require('./src/draw-graph/draw-graph'); | ||
var logWhatIChange = require('./src/what-i-change/what-i-change'); | ||
var logWhatChangesMe = require('./src/what-changes-me/what-changes-me'); | ||
var getWhatIChange = require('./src/get-what-i-change/get-what-i-change'); | ||
var getWhatChangesMe = require('./src/get-what-changes-me/get-what-changes-me'); | ||
module.exports = namespace.debug = { | ||
getGraph: temporarilyBind(getGraph), | ||
formatGraph: temporarilyBind(formatGraph), | ||
drawGraph: temporarilyBind(drawGraph), | ||
getWhatIChange: temporarilyBind(getWhatIChange), | ||
getWhatChangesMe: temporarilyBind(getWhatChangesMe), | ||
logWhatIChange: temporarilyBind(logWhatIChange), | ||
logWhatChangesMe: temporarilyBind(logWhatChangesMe) | ||
}; | ||
window.can = Proxy != null ? proxyNamespace(namespace) : namespace; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*can-debug@1.0.1#src/draw-graph/draw-graph*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'./format-graph', | ||
'../get-graph/get-graph' | ||
], function (require, exports, module) { | ||
(function (__dirname, require, exports, module) { | ||
var formatGraph = require('./format-graph'); | ||
var getGraph = require('../get-graph/get-graph'); | ||
module.exports = function drawGraph(obj, key) { | ||
var gotKey = arguments.length === 2; | ||
var graph = gotKey ? getGraph(obj, key) : getGraph(obj); | ||
fetch(__dirname + '/vis.js').then(function (res) { | ||
return res.text(); | ||
}).then(function (code) { | ||
var w = window.open('', 'can-debug: Dependency Graph'); | ||
var doc = w.document; | ||
var script = doc.createElement('script'); | ||
script.text = code; | ||
doc.body.appendChild(script); | ||
var data = formatGraph(graph); | ||
var drawScript = doc.createElement('script'); | ||
drawScript.text = ` | ||
var container = document.createElement("div"); | ||
var options = { | ||
physics: { | ||
solver: "repulsion" | ||
} | ||
}; | ||
document.title = "can-debug: Dependency Graph"; | ||
document.body.appendChild(container); | ||
new vis.Network( | ||
container, | ||
{ | ||
nodes: new vis.DataSet(${ JSON.stringify(data.nodes) }), | ||
edges: new vis.DataSet(${ JSON.stringify(data.edges) }) | ||
}, | ||
options | ||
); | ||
`; | ||
doc.body.appendChild(drawScript); | ||
}); | ||
}; | ||
}('/', require, exports, module)); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*can-debug@1.0.1#src/draw-graph/format-graph*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-reflect' | ||
], function (require, exports, module) { | ||
var canReflect = require('can-reflect'); | ||
module.exports = function formatGraph(graph) { | ||
var nodeIdMap = new Map(graph.nodes.map(function (node, index) { | ||
return [ | ||
node, | ||
index + 1 | ||
]; | ||
})); | ||
var nodesDataSet = graph.nodes.map(function (node) { | ||
return { | ||
shape: 'box', | ||
id: nodeIdMap.get(node), | ||
label: canReflect.getName(node.obj) + (node.key ? '.' + node.key : '') | ||
}; | ||
}); | ||
var getArrowData = function getArrowData(meta) { | ||
var regular = { arrows: 'to' }; | ||
var withDashes = { | ||
arrows: 'to', | ||
dashes: true | ||
}; | ||
var map = { | ||
derive: regular, | ||
mutate: withDashes | ||
}; | ||
return map[meta.kind]; | ||
}; | ||
var visited = new Map(); | ||
var arrowsDataSet = []; | ||
graph.nodes.forEach(function (node) { | ||
var visit = function (node) { | ||
if (!visited.has(node)) { | ||
visited.set(node, true); | ||
var arrows = graph.arrows.get(node); | ||
var headId = nodeIdMap.get(node); | ||
arrows.forEach(function (neighbor) { | ||
var tailId = nodeIdMap.get(neighbor); | ||
var meta = graph.arrowsMeta.get(node).get(neighbor); | ||
arrowsDataSet.push(Object.assign({ | ||
from: headId, | ||
to: tailId | ||
}, getArrowData(meta))); | ||
visit(neighbor); | ||
}); | ||
} | ||
}; | ||
visit(node); | ||
}); | ||
return { | ||
nodes: nodesDataSet, | ||
edges: arrowsDataSet | ||
}; | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*can-debug@1.0.1#src/get-data/get-data*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'../label-cycles/label-cycles' | ||
], function (require, exports, module) { | ||
var labelCycles = require('../label-cycles/label-cycles'); | ||
var isDisconnected = function isDisconnected(data) { | ||
return !data.derive.length && !data.mutations.length && !data.twoWay.length; | ||
}; | ||
module.exports = function getDebugData(inputGraph, direction) { | ||
var visited = new Map(); | ||
var graph = labelCycles(direction === 'whatChangesMe' ? inputGraph.reverse() : inputGraph); | ||
var visit = function visit(node) { | ||
var data = { | ||
node: node, | ||
derive: [], | ||
mutations: [], | ||
twoWay: [] | ||
}; | ||
visited.set(node, true); | ||
graph.getNeighbors(node).forEach(function (adj) { | ||
var meta = graph.getArrowMeta(node, adj); | ||
if (!visited.has(adj)) { | ||
switch (meta.kind) { | ||
case 'twoWay': | ||
data.twoWay.push(visit(adj)); | ||
break; | ||
case 'derive': | ||
data.derive.push(visit(adj)); | ||
break; | ||
case 'mutate': | ||
data.mutations.push(visit(adj)); | ||
break; | ||
default: | ||
throw new Error('Unknow meta.kind value: ', meta.kind); | ||
} | ||
} | ||
}); | ||
return data; | ||
}; | ||
var result = visit(graph.nodes[0]); | ||
return isDisconnected(result) ? null : result; | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/*can-debug@1.0.1#src/get-graph/get-graph*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'../graph/graph', | ||
'./make-node', | ||
'can-reflect', | ||
'can-reflect-dependencies' | ||
], function (require, exports, module) { | ||
var Graph = require('../graph/graph'); | ||
var makeNode = require('./make-node'); | ||
var canReflect = require('can-reflect'); | ||
var mutateDeps = require('can-reflect-dependencies'); | ||
module.exports = function getGraph(obj, key) { | ||
var order = 0; | ||
var graph = new Graph(); | ||
var gotKey = arguments.length === 2; | ||
var addArrow = function addArrow(direction, parent, child, meta) { | ||
switch (direction) { | ||
case 'whatIChange': | ||
graph.addArrow(parent, child, meta); | ||
break; | ||
case 'whatChangesMe': | ||
graph.addArrow(child, parent, meta); | ||
break; | ||
default: | ||
throw new Error('Unknown direction value: ', meta.direction); | ||
} | ||
}; | ||
var visitKeyDependencies = function visitKeyDependencies(source, meta, cb) { | ||
canReflect.eachKey(source.keyDependencies || {}, function (keys, obj) { | ||
canReflect.each(keys, function (key) { | ||
cb(obj, meta, key); | ||
}); | ||
}); | ||
}; | ||
var visitValueDependencies = function visitValueDependencies(source, meta, cb) { | ||
canReflect.eachIndex(source.valueDependencies || [], function (obj) { | ||
cb(obj, meta); | ||
}); | ||
}; | ||
var visit = function visit(obj, meta, key) { | ||
var gotKey = arguments.length === 3; | ||
var node = graph.findNode(function (node) { | ||
return gotKey ? node.obj === obj && node.key === key : node.obj === obj; | ||
}); | ||
if (node) { | ||
if (meta.parent) { | ||
addArrow(meta.direction, meta.parent, node, { | ||
kind: meta.kind, | ||
direction: meta.direction | ||
}); | ||
} | ||
return graph; | ||
} | ||
order += 1; | ||
node = gotKey ? makeNode(obj, key) : makeNode(obj); | ||
node.order = order; | ||
graph.addNode(node); | ||
if (meta.parent) { | ||
addArrow(meta.direction, meta.parent, node, { | ||
kind: meta.kind, | ||
direction: meta.direction | ||
}); | ||
} | ||
var nextMeta; | ||
var data = gotKey ? mutateDeps.getDependencyDataOf(obj, key) : mutateDeps.getDependencyDataOf(obj); | ||
if (data && data.whatIChange) { | ||
nextMeta = { | ||
direction: 'whatIChange', | ||
parent: node | ||
}; | ||
canReflect.eachKey(data.whatIChange, function (dependencyRecord, kind) { | ||
nextMeta.kind = kind; | ||
visitKeyDependencies(dependencyRecord, nextMeta, visit); | ||
visitValueDependencies(dependencyRecord, nextMeta, visit); | ||
}); | ||
} | ||
if (data && data.whatChangesMe) { | ||
nextMeta = { | ||
direction: 'whatChangesMe', | ||
parent: node | ||
}; | ||
canReflect.eachKey(data.whatChangesMe, function (dependencyRecord, kind) { | ||
nextMeta.kind = kind; | ||
visitKeyDependencies(dependencyRecord, nextMeta, visit); | ||
visitValueDependencies(dependencyRecord, nextMeta, visit); | ||
}); | ||
} | ||
return graph; | ||
}; | ||
return gotKey ? visit(obj, {}, key) : visit(obj, {}); | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*can-debug@1.0.1#src/get-graph/make-node*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'can-reflect' | ||
], function (require, exports, module) { | ||
var canReflect = require('can-reflect'); | ||
module.exports = function makeNode(obj, key) { | ||
var gotKey = arguments.length === 2; | ||
var node = { | ||
obj: obj, | ||
name: canReflect.getName(obj), | ||
value: gotKey ? canReflect.getKeyValue(obj, key) : canReflect.getValue(obj) | ||
}; | ||
if (gotKey) { | ||
node.key = key; | ||
} | ||
return node; | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*can-debug@1.0.1#src/get-what-changes-me/get-what-changes-me*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'../get-data/get-data', | ||
'../get-graph/get-graph' | ||
], function (require, exports, module) { | ||
var getData = require('../get-data/get-data'); | ||
var getGraph = require('../get-graph/get-graph'); | ||
module.exports = function getWhatChangesMe(obj, key) { | ||
var gotKey = arguments.length === 2; | ||
return getData(gotKey ? getGraph(obj, key) : getGraph(obj), 'whatChangesMe'); | ||
}; | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*can-debug@1.0.1#src/get-what-i-change/get-what-i-change*/ | ||
define([ | ||
'require', | ||
'exports', | ||
'module', | ||
'../get-data/get-data', | ||
'../get-graph/get-graph' | ||
], function (require, exports, module) { | ||
var getData = require('../get-data/get-data'); | ||
var getGraph = require('../get-graph/get-graph'); | ||
module.exports = function getWhatChangesMe(obj, key) { | ||
var gotKey = arguments.length === 2; | ||
return getData(gotKey ? getGraph(obj, key) : getGraph(obj), 'whatIChange'); | ||
}; | ||
}); |
Oops, something went wrong.