Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. function E(node) {
  2. function isChildren(x) { return x instanceof Array; }
  3. function isText(x) { return typeof x === "string"; }
  4.  
  5. if(!(node instanceof Array))
  6. return node;
  7.  
  8. var element = node[0];
  9. var props = null;
  10. var text = null;
  11. var children = null;
  12.  
  13. if(node.length > 1) {
  14. if(isChildren(node[1])) {
  15. children = node[1].map(E);
  16. } else if(isText(node[1])) {
  17. text = node[1];
  18. if(isChildren(node[2])) {
  19. children = node[2].map(E);
  20. }
  21. } else if(node.length == 2) {
  22. props = node[1];
  23. } else if(isChildren(node[2])) {
  24. props = node[1];
  25. children = node[2].map(E);
  26. } else if(isText(node[2])) {
  27. props = node[1];
  28. text = node[2];
  29. if(isChildren(node[3])) {
  30. children = node[3].map(E);
  31. }
  32. }
  33. }
  34. return React.createElement(element, props, text, children);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement