Message from JavaScript discussions

April 2017

— I further abstracted from the iterator protocol by providing my own strategy pattern on top of it

— 

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();

— 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

Message permanent page

— 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