Skip to content

Commit

Permalink
add DOM utilities and initial update
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 29, 2018
1 parent f05b028 commit 4d53a3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { compile } from "./compiler/compiler";
import { config } from "./util/config";
import { newM } from "./util/m";

let components = {};

Expand All @@ -18,12 +19,12 @@ export default function Moon(root, view) {
create: view[0],
mount: view[1],
update: view[2],
m: []
m: newM()
};

instance.create();
instance.mount(root);
root.parentNode.removeChild(root);
instance.update();

return instance;
}
Expand All @@ -40,7 +41,7 @@ Moon.extend = (name, view, data) => {
create: view[0],
mount: view[1],
update: view[2],
m: []
m: newM()
};
};
};
Expand Down
19 changes: 19 additions & 0 deletions src/util/m.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const createElement = (type) => document.createElement(type);
const createTextNode = (content) => document.createTextNode(content);

const mountAppendChild = (element, parent) => {
parent.appendChild(element);
};

const updateTextContent = (element, content) => {
element.textContent = content;
};

export const newM = () => {
let m = [];
m.ce = createElement;
m.ct = createTextNode;
m.ma = mountAppendChild;
m.ut = updateTextContent;
return m;
};

0 comments on commit 4d53a3c

Please sign in to comment.