Skip to content

Instantly share code, notes, and snippets.

View Mandrewdarts's full-sized avatar

M. Andrew Darts Mandrewdarts

View GitHub Profile
@Mandrewdarts
Mandrewdarts / proxy-store.js
Last active October 20, 2020 18:50
Store using Proxies
const createStore = (initialState = {}) => {
let subs = [];
const state = new Proxy(initialState, {
set(oldState, prop, value ) {
oldState[prop] = value;
subs.forEach(fn => fn(oldState));
return true;
}
})
@Mandrewdarts
Mandrewdarts / remove-children.js
Created October 21, 2020 02:30
Remove all children of element
while (parent.firstChild) {
parent.firstChild.remove()
}
@Mandrewdarts
Mandrewdarts / createElement.js
Created October 23, 2020 22:40
Create Element Util
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;
}