This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (parent.firstChild) { | |
parent.firstChild.remove() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createStore = (initialState = {}) => { | |
let subs = []; | |
const state = new Proxy(initialState, { | |
set(oldState, prop, value ) { | |
oldState[prop] = value; | |
subs.forEach(fn => fn(oldState)); | |
return true; | |
} | |
}) | |