Coder Social home page Coder Social logo

compute-js's People

Contributors

iamnoah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tommymorgan

compute-js's Issues

Custom Equality

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.

Refactor: Manage as a digraph instead of observers.

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
},

start/end transaction

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?)

Backbone.Collections

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).

Should not notify listeners or other computes while recomputing

strict digraph dependencies {A -> B; B -> C; D -> B; D -> C; A -> F; F -> R; C -> R; }

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

log graph to console

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;
}

Connect to other computes

CanJS and Knockout both have computes with "compute nature" so it should be possible to generically connect them.

Viz improvements

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.