View createElement.js
export function createElement(el = 'div', attributes = {}, innerEls = []) { | |
const element = document.createElement(el); | |
if (attributes.class) { | |
attributes.class.forEach((c) => element.classList.add(c)); | |
} | |
if (attributes.id) { | |
element.id = attributes.id; | |
} |
View remove-children.js
while (parent.firstChild) { | |
parent.firstChild.remove() | |
} |
View proxy-store.js
const createStore = (initialState = {}) => { | |
let subs = []; | |
const state = new Proxy(initialState, { | |
set(oldState, prop, value ) { | |
oldState[prop] = value; | |
subs.forEach(fn => fn(oldState)); | |
return true; | |
} | |
}) | |