Message from JavaScript talks

April 2017

— Weirder albeit cool is the way this is made:

var myAlgo = new Strategy(

  (rootTuple) => {rootTuple.clone = cloneRoot},

  (tuple, accessor, exists, isObj, done) => { ... }

);

var result = myAlgo.run();

Message permanent page

— 

Top parameter is the init function, it gets run on the root tuple of the stack, at which point any algorithm can add any objects it wants the DFS to also traverse

— Bottom parameter is the main procedure which gets run per-iteration

— I replaced that weird null stuff with an easier way... done was if the iterator's done property is true which means it's value is not set, thus you cannot send anything if done is true. Instead now the DFS predict when it is currently iterating the last node, and sends an additional property in it's shared state object called isLast.

Message permanent page

— Like this

if (condition allowing new node in stack) {
// Add new nodes to stack
} else if (stack is empty) {
isLast = true;
}

Message permanent page

— Https://pastebin.com/ux7ntFpG

— Oh, I notice an old comment about cloning... haha

— These are generic, no cloning going on :p

— What now

— 

var myAlg = new Strategy(null,

  function (state) {

    console.log(state);

  }

);

myAlg.traverseAlg = function* (object) {

  for (var loc in object) {

    yield object[loc];

  }

};

myAlg.run({property: "Hello World!"});

bam

Message permanent page

— Needs some tweaking, but this is looking nice

— Allows decoupled behavior from the main algorithm