Skip to content

Instantly share code, notes, and snippets.

Avatar

M. Andrew Darts Mandrewdarts

View GitHub Profile
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;
}
@Mandrewdarts
Mandrewdarts / remove-children.js
Created Oct 21, 2020
Remove all children of element
View remove-children.js
while (parent.firstChild) {
parent.firstChild.remove()
}
@Mandrewdarts
Mandrewdarts / proxy-store.js
Last active Oct 20, 2020
Store using Proxies
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;
}
})