import { compile } from "./compiler/compiler";
import { config } from "./util/config";

let components = {};

export default function Moon(element, view) {
  if (typeof element === "string") {
    element = document.querySelector(element);
  }

  if (typeof view === "string") {
    view = compile(view);
  }

  view[0]();
  view[1]();
  view[2]();
}

Moon.extend = (name, view, data) => {
  if (typeof view === "string") {
    view = compile(view);
  }

  components[name] = () => {
    return {
      name: name,
      data: data(),
      create: view[0],
      mount: view[1],
      update: view[2],
      m: []
    };
  };
};

Moon.compile = compile;
Moon.config = config;

@@ -309,43 +309,236 @@
 %0A%0A  
-view%5B0%5D();%0A  view%5B1%5D();%0A  view%5B2%5D()
+const instance = %7B%0A    name: %22@%22,%0A    data: %7B%7D,%0A    create: view%5B0%5D,%0A    mount: view%5B1%5D,%0A    update: view%5B2%5D,%0A    m: %5B%5D%0A  %7D;%0A%0A  instance.create();%0A  instance.mount();%0A  element.parentNode.removeChild(element);%0A%0A  return instance
 ;%0A%7D%0A

add root instance