iamnoah / compute-js Goto Github PK
View Code? Open in Web Editor NEWA standalone computed function implementation.
A standalone computed function implementation.
For computes that return an object or array, it would be useful to be able to specify a custom function that determines if the old and new values are equal, to prevent a change from firing.
Not something that I would recommend by default though, as recomputing is often cheaper than deep object comparison.
Instead of using the observer pattern internally, a graph of all computes should be maintained. Then a dirty sweep and a recompute sweep can be done on the graph. No external API changes.
Maybe (slightly redundant, but fast):
var INCOMING = 1; // bitmasks
var OUTGOING = 2;
$id: {
$neighborId: INCOMING, // $id is depended on by $neighborId
$otherNeighborId: OUTGOING, // $id depends on $otherNeighborId
},
A transaction is different from a batch in that no return values should change until the transaction finishes. (could this matter with the current batch functionality?)
In backbone-compute, Collections are not observable.
Need to observe add
, sort
, and remove
whenever get
, at
, toJSON
, where
, findWhere
or any underscore method is called. findWhere
and where
access models with .get
so we don't need to worry about change
(for the models).
R changes, F and C are dirty. Recompute F, F changes, so A recomputes. A calls B, which also needs to recompute. B calls C. C is dirty, so it recomputes its value and notifies D (then B). D recomputes and calls B. B is currently recomputing. Disaster.
The problem is the notifications in the middle. Can work around easily enough by batching around R:
compute.startBatch();
R.set(newValue);
compute.endBatch();
Need to fix this in #6
var Viz = require("viz.js");
var ctx = new Canvas(...)
var img = new Image();
img.onload = function() {
ctx.drawImage(img, 0, 0);
console.screenshot(ctx);
}
img.src = dataUri(Viz(graph, "svg"));
function dataUri(svg) {
return "data:image/svg+xml;utf8," + svg;
}
CanJS and Knockout both have computes with "compute nature" so it should be possible to generically connect them.
: and - are invalid in node names.
Depends on Refactoring (#6)
startViz/stopViz - captures what was accessed and set/rebound in between (all accessed computes are bound for the duration)
non-strict digraph.
access is shown as a normal graph, black edges.
If a value was set, the node is filled with a color.
An edge of the same color is added between the changed node and any dependencies that changed their value (and so on for their dependencies.) The changed nodes get the fill color.
Any net new dependencies are added in the same color with a dashed edge.
Any removed dependencies add an edge in the same color with a dotted edge and inverse arrow.
Each set is a new color. Nodes that end up with more than one color will get wedged. Multiple edges will be drawn for each color.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.