Skip to content

Instantly share code, notes, and snippets.

@SanderSpies
Created October 24, 2013 07:24
Show Gist options
  • Save SanderSpies/7132734 to your computer and use it in GitHub Desktop.
Save SanderSpies/7132734 to your computer and use it in GitHub Desktop.
Graph Idea
var graphDefinition = {
'somewhere': 'there is a ${./over/therainbow}',
'over':{
'therainbow' : 'pot of gold'
},
'value': 'genius',
'act':{
'of': '${../value}'
}
};
var Graph = (function(){
var graph;
var Graph = function(def){
graph = def;
};
function translate(graph){
return graph;
}
Graph.prototype = {
mutate: function(func){
var newGraph = func.call(func, Object.create(graph));
console.log("original was not changed:", !graph.changed);
console.log("we have potentially a new graph:", newGraph);
// find differentials and update the source for the differential
// perhaps make it part of a mutate cycle that combines multiple mutations at once?
// broadcast mutation
},
read: function(func){
var translatedGraph = Object.freeze(Object.create(translate(graph)));
func.call(func, translatedGraph);
},
getChildGraph: function(){
}
};
return Graph;
})();
var testGraph = new Graph(graphDefinition);
testGraph.read(function(graph){
graph.x = true;
console.log("mutating is not allowed here:", !graph.x);
});
testGraph.mutate(function(graph){
graph.changed = "true";
return graph;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment