Created
October 24, 2013 07:24
-
-
Save SanderSpies/7132734 to your computer and use it in GitHub Desktop.
Graph Idea
This file contains hidden or 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 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