Easystar.js, Boolasync, Synchroscope

10 Jun 2013 | By Alex Young | Tags angularjs libraries node async

Easystar.js

easystar

Easystar.js (GitHub: prettymuchbryce / easystarjs, License: MIT) by Bryce Neal is an A* pathfinding API. Given a map of tiles, easystar will find a path through traversable tiles on the grid:

var easystar = new EasyStar.js();
var grid = [[0,0,1,0,0],
            [0,0,1,0,0],
            [0,0,1,0,0],
            [0,0,1,0,0],
            [0,0,0,0,0]];

easystar.setGrid(grid);
easystar.setAcceptableTiles([0]);

easystar.findPath(0, 0, 4, 0, function(path)) {
  if (path === null) {
    console.log('Path was not found.');
  } else {
    console.log('Path was found. The first Point is:', path[0]);
  }
});

easystar.setIterationsPerCalculation(1000); 
easystar.calculate()

The readme has a full breakdown of the methods used in this example, and installation instructions.

Boolasync

Boolasync (GitHub: olalonde / boolasync, License: MIT, npm: boolasync) by Olivier Lalonde is a module for composing logic using chained calls to asynchronous functions:

fn1.and(fn2).or(fn3).and(fn4.orNot(fn5).and(fn6)).eval(function(err, res) {
  if (err) return console.error(err);
  if (res) {
    console.log('The expression evaluated to true.');
  } else {
    console.log('The expression evaluated to false.');
  }
});

It supports optional “monkey patching” which adds boolean logic methods to Function.prototype. Olivier has included Mocha tests and a roadmap for future features.

synchroscope

synchroscope (GitHub: dtinth / synchroscope, License: MIT, npm: synchroscope) by Thai Pangsakulyanont allows the scope to be shared between multiple AngularJS clients. It works by sending data encoded using JSON.stringify over Socket.IO.

There’s a synchroscope instance running on Nodejitsu so you can try out examples using jsFiddle and similar services. The author has asked Nodejitsu for an open source drone but is currently waiting for a response. He’s got two demos running: AngularJS Todos and Tic Tac Toe Game.

The bundled server stores everything in-memory, so it doesn’t currently scale across multiple processes. I imagine the server could easily be modified to use a database or perhaps pub/sub.

On the client the API is surprisingly minimal – once the $ync dependency has been added, data can be shared from $scope by calling $ync($scope, keys, room). It seems like an idiomatic way to make real-time web applications with AngularJS.


blog comments powered by Disqus