Last active
April 3, 2025 20:20
-
-
Save henriquegogo/0fb36f804b57c029ba4a7b19280bc040 to your computer and use it in GitHub Desktop.
Revisions
-
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,13 +24,8 @@ function HelloWorld(message = 'Hello World!', buttonLabel = 'Click me!') { return { update, dispatch } = handleEvents( div( h1({ onclick: () => update('Bye bye') }, message), button({ onclick: () => dispatch('newdata', 'Clicked') }, buttonLabel) ) ); } -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 8 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,9 +4,8 @@ const ElementBuilder = new Proxy({}, { get: (_, tagName) => (...args) => { return element; }}); const EventHandler = (element, fn) => Object.assign(element || {}, { update: (...newProps) => element.replaceWith(fn(...newProps)), listen: (eventType, handler) => (element.dataset.event = "", element) .addEventListener(eventType, ({ detail }) => handler(detail)), dispatch: (eventType, detail) => document.querySelectorAll("[data-event]") @@ -15,23 +14,23 @@ const EventHandler = (fn, element) => Object.assign(element || {}, { const { div, h1, button } = ElementBuilder; function HelloWorld(message = 'Hello World!', buttonLabel = 'Click me!') { const handleEvents = (element) => { const { listen, update } = EventHandler(element, HelloWorld); listen('newdata', update); listen('newdata', () => console.log('gotcha!')); return element; }; return { update, dispatch } = handleEvents( div( h1({ className: 'hello-world', onclick: () => update('Bye bye') }, message), button({ onclick: () => dispatch('newdata', 'Clicked') }, buttonLabel) ) ); } -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 8 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,23 +16,24 @@ const EventHandler = (fn, element) => Object.assign(element || {}, { const { div, h1, button } = ElementBuilder; function HelloWorld(message = 'Hello World!') { const handleEvents = (element) => { const { self, listen, update } = EventHandler(HelloWorld, element); listen('newdata', update); listen('newdata', () => console.log('gotcha!')); return self; }; return { update, dispatch } = handleEvents( div( h1({ className: 'hello-world', onclick: () => update('Bye bye') // `update` is now inside `handleEvents` }, message), button({ onclick: () => dispatch('newdata', 'Bye bye') }, 'Click here') ) ); } document.body.append(HelloWorld()); -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 20 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,29 +4,35 @@ const ElementBuilder = new Proxy({}, { get: (_, tagName) => (...args) => { return element; }}); const EventHandler = (fn, element) => Object.assign(element || {}, { self: element, update: (newProps) => element.replaceWith(fn(newProps)), listen: (eventType, handler) => (element.dataset.event = "", element) .addEventListener(eventType, ({ detail }) => handler(detail)), dispatch: (eventType, detail) => document.querySelectorAll("[data-event]") .forEach(el => el.dispatchEvent(new CustomEvent(eventType, { detail }))) }); const { div, h1, button } = ElementBuilder; function HelloWorld(message = 'Hello World!') { const handleEvents = ({ self, listen, update }) => { listen('newdata', update); listen('newdata', () => console.log('gotcha!')); return self; } return handleEvents({ update, dispatch } = EventHandler(HelloWorld, div( h1({ className: 'hello-world', onclick: () => update('Bye bye') }, message), button({ onclick: () => dispatch('newdata', 'Bye bye') }, 'Click here') ) )); } document.body.append(HelloWorld()); -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,8 +19,7 @@ function HelloWorld(message = 'Hello World!') { h1({ className: 'hello-world', onclick: () => dispatch('newdata', 'Bye bye') }, message)); const { update, listen, dispatch } = EventManager(element, HelloWorld); -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 5 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,8 @@ const ElementBuilder = new Proxy({}, { get: (_, tagName) => (...args) => { const element = Object.assign(document.createElement(tagName), ...args); element.append(...args.filter(arg => arg.constructor !== Object)); return element; }}); const EventManager = (element, fn) => ({ update: props => element.replaceWith(fn(props)), -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ const ElementBuilder = new Proxy({}, { get: (_, tagName) => function(...args) { const element = Object.assign(document.createElement(tagName), ...args); element.append(...args.filter(arg => arg.constructor !== Object)); return element; } }); -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 9 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ const ElementBuilder = new Proxy({}, { get: (_, tagName) => function(...args) { const element = document.createElement(tagName); args.forEach(arg => arg.constructor === Object ? Object.assign(element, arg) : arg.constructor === Function ? arg(element) : element.append(arg)); return element; } }); @@ -17,18 +19,19 @@ const EventManager = (element, fn) => ({ const { div, h1 } = ElementBuilder; function HelloWorld(message = 'Hello World!') { const element = div( h1({ className: 'hello-world', onclick: () => dispatch('newdata', 'Bye bye') }, message), () => console.log('after')); const { update, listen, dispatch } = EventManager(element, HelloWorld); listen('newdata', update); listen('newdata', () => console.log('gotcha!')); return element; } document.body.append(HelloWorld()); -
henriquegogo revised this gist
Apr 3, 2025 . 2 changed files with 34 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ const ElementBuilder = new Proxy({}, { get: (_, tagName) => function(...args) { const element = Object.assign(document.createElement(tagName), ...args); element.append(...args.filter(arg => arg.constructor !== Object)); return element; } }); const EventManager = (element, fn) => ({ update: props => element.replaceWith(fn(props)), listen: (eventType, handler) => (element.dataset.event = "", element) .addEventListener(eventType, ({ detail }) => handler(detail)), dispatch: (eventType, detail) => document.querySelectorAll("[data-event]") .forEach(el => el.dispatchEvent(new CustomEvent(eventType, { detail }))) }); const { div, h1 } = ElementBuilder; function HelloWorld(message = 'Hello World!') { const container = div( h1({ className: 'hello-world', onclick: () => dispatch('newdata', 'Bye bye') }, message)); const { update, listen, dispatch } = EventManager(container, HelloWorld); listen('newdata', update); listen('newdata', () => console.log('gotcha!')); return container; } document.body.append(HelloWorld()); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,34 +0,0 @@ -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 16 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,28 +6,29 @@ const ElementCreator = new Proxy({}, { } }); const EventsHandler = (el, fn) => ({ update: props => el.replaceWith(fn(props)), listen: (ev, listener) => (el.dataset.event = "", el) .addEventListener(ev, ({detail}) => listener(detail)), dispatch: (ev, detail) => document.querySelectorAll("[data-event]") .forEach(el => el.dispatchEvent(new CustomEvent(ev, {detail}))) }); const { div, h1 } = ElementCreator; function HelloWorld(message = 'Hello World!') { const self = div( h1({ className: 'hello-world', onclick: () => dispatch('newdata', 'Bye bye') }, message)); const { update, listen, dispatch } = EventsHandler(self, HelloWorld); listen('newdata', update); listen('newdata', () => console.log('gotcha!')); return self; } document.body.append(HelloWorld()); -
henriquegogo revised this gist
Apr 3, 2025 . 1 changed file with 20 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,33 @@ const ElementCreator = new Proxy({}, { get: (_, tag) => function(...args) { const el = Object.assign(document.createElement(tag), ...args); el.append(...args.filter(arg => arg.constructor !== Object)); return el; } }); const EventsHandler = (fn, el) => ({ update: (newElement) => el.replaceWith(fn(newElement)), listen: (ev, fn) => (el.dataset.event = "", el) .addEventListener(ev, ({detail}) => fn(detail)), dispatch: (ev, detail) => document.querySelectorAll("[data-event]") .forEach(el => el.dispatchEvent(new CustomEvent(ev, {detail}))) }); const HelloWorld = (message = 'Hello World!') => { const { div, h1 } = ElementCreator; const el = div({ className: 'hello-world', onclick: () => dispatch('newdata', 'Bye bye') }, h1(message)); const { update, listen, dispatch } = EventsHandler(HelloWorld, el); listen('newdata', newMsg => update(newMsg)); listen('newdata', () => console.log('gotcha!')); return el; } document.body.append(HelloWorld()); -
henriquegogo revised this gist
Apr 2, 2025 . 2 changed files with 30 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ const ElementFunction = new Proxy({}, { get: (_, tag) => (...args) => { const dispatch = (ev, detail) => document.querySelectorAll("[data-event]") .forEach(el => el.dispatchEvent(new CustomEvent(ev, {detail}))); if (tag === 'dispatch') return dispatch(...args); const el = Object.assign(document.createElement(tag), ...args); el.append(...args.filter(arg => arg.constructor !== Object)); el.update = (newElement) => el.replaceWith(newElement); el.listen = (ev, fn) => (el.dataset.event = "", el) .addEventListener(ev, ({detail}) => fn(detail)); el.dispatch = dispatch; return el; } }); const Hello = (message = 'Hello World!') => { const { div, h1 } = ElementFunction; const { update, listen, dispatch } = el = div({ className: 'hello-world', onclick: () => dispatch('newdata', 'Bye bye'), }, h1(message)); listen('newdata', (newMsg) => update(Hello(newMsg))); return el; } document.body.append(Hello()); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +0,0 @@ -
henriquegogo created this gist
Sep 1, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ 'a abbr address area article aside audio b base bdi bdo blockquote body br \ button canvas caption cite code col colgroup data datalist dd del details dfn \ dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 \ h5 h6 head header hgroup hr html i iframe img input ins kbd label legend li \ link main map mark math menu meta meter nav noscript object ol optgroup option \ output p param picture pre progress q rp rt ruby s samp script section select \ slot small source span strong style sub summary sup svg table tbody td \ template textarea tfoot th thead time title tr track u ul var video wbr \ '.split(' ').forEach(tag => window[tag] = (...args) => { const el = Object.assign(document.createElement(tag), ...args); el.append(...args.filter(arg => arg.constructor !== Object)); return el; });