Skip to content

Instantly share code, notes, and snippets.

@c9s
Last active July 11, 2016 10:28
Show Gist options
  • Save c9s/2867c4a37bd30132ed70bc480056950e to your computer and use it in GitHub Desktop.
Save c9s/2867c4a37bd30132ed70bc480056950e to your computer and use it in GitHub Desktop.
var QATree = function(states) {
  this.states = states || {};
};
QATree.prototype.state = function(code, state) {
this.states[code] = state;
return code;
};
QATree.prototype.get = function(code) {
return this.states[code];
};
QATree.prototype.next = function(a, current) {
    return current.answers[a];
};
QATree.prototype.query = function(input, current) {
   if (input.length == 0) {
     return current;
   }
   var a = input.shift();
   var next = this.next(a, current);
   return ! next ? current : 
       this.query(input, next);
};
QATree.protoype.run = function(input) {
   var state = this.states[0];
   return this.query(input, state);
};
var tree = new QATree();
tree.state("Q1", {
   question: "Q1",
   payload: "anything",
   answers: {
      "Yes": tree.state("Q2", { ... }),
      "No": tree.state("Q3", {...})
   }
});
var last = tree.run([ "Yes", "No" ]);
console.log(last.payload);
import React from "react";
var Question = React.createClass({
   componentWillMount: function() {},
   componentWillUnmount: function() {},
   render: function() {
       
   }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment