{"id":18553688,"url":"https://github.com/websemantics/hyperapp-lifecycle","last_synced_at":"2025-04-09T23:30:46.783Z","repository":{"id":47344898,"uuid":"217753321","full_name":"websemantics/hyperapp-lifecycle","owner":"websemantics","description":"Small wrapper for Hyperapp and Superfine to emulate 'connected' and 'disconnected' lifecycle events.","archived":false,"fork":false,"pushed_at":"2022-07-20T16:39:38.000Z","size":18,"stargazers_count":6,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T13:21:24.095Z","etag":null,"topics":["hyperapp","lifecycle","superfine"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/websemantics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-26T18:37:50.000Z","updated_at":"2021-11-30T04:22:39.000Z","dependencies_parsed_at":"2022-09-10T01:51:23.221Z","dependency_job_id":null,"html_url":"https://github.com/websemantics/hyperapp-lifecycle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websemantics%2Fhyperapp-lifecycle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websemantics%2Fhyperapp-lifecycle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websemantics%2Fhyperapp-lifecycle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/websemantics%2Fhyperapp-lifecycle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/websemantics","download_url":"https://codeload.github.com/websemantics/hyperapp-lifecycle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247959798,"owners_count":21024842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hyperapp","lifecycle","superfine"],"created_at":"2024-11-06T21:17:57.716Z","updated_at":"2025-04-09T23:30:46.444Z","avatar_url":"https://github.com/websemantics.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"```\n                                 ╭──╮ ╭───┬╮ ╭────╮\n                            ╭──╮ ├──┤ │    │ │ ─  │ ╭────╮\n  ╭────◉  connected         │  │ │  │ │   ─┤ │    │ │ ╭──╯ ╭──╮╭╮\n  │                         │  │ │  │ │   ╭╯ │ `○─┤ │ ╰──╮ │  │││ ╭────╮\n╭─┴─╮  ╭──╮╭╮               │  │ ╰──╯ ╰───╯  ╰────╯ │    │ │  ╰╯│ │ ╭──╯ ╭──╮ ╭────╮\n│   ╰╮ │  │││ ╭────╮        ╰──╯                    ╰────╯ ├─── │ │ ╰──╮ │  │ │ ○  │\n│    │ │  ╰╯│ │  ╭╮│ ╭────╮         \\||/  ╭────╮ ╭────╮    ╰────╯ │    │ │  │ │    │\n│  ╭╮│ ├──○ │ │  ╰╯│ │ ─  │ ╭──┬─╮ ╭(oo)╮ │  ╭╮│ │  ╭╮│           ╰────╯ │  │ │ ───┤\n╰──╯╰╯ ╰────╯ │   ╭╯ │    │ │    │ ├─── │ │  ╰╯│ │  ╰╯│                  ╰──╯ ╰──┬─╯\n              ╰───╯  │ ───┤ │   ╭╯ │╭╮  │ │   ╭╯ │   ╭╯    disconnected  ◉───────╯\n                     ╰────╯ │   │  │╰╯  │ ╰───╯  ╰───╯\n                            ╰───╯  ╰──┴─╯\n```\n\n\u003e Small wrapper for Hyperapp and Superfine to emulate `connected` and `disconnected` lifecycle events.\n\n[![Hyperapp demo](https://img.shields.io/badge/Hyperapp%20demo-%E2%86%92-9D6EB3.svg?style=flat-square)](https://websemantics.github.io/hyperapp-lifecycle/demo/hyperapp.html)\n\n[![Superfine demo](https://img.shields.io/badge/Superfine%20demo-%E2%86%92-9D6EB3.svg?style=flat-square)](https://websemantics.github.io/hyperapp-lifecycle/demo/superfine.html)\n\n## Overview\n\n[Hyperapp](https://github.com/jorgebucaran/hyperapp) is super tiny ui framework that is centered around app state with awesome flexibility and rich ecosystem. With super lean code however, it is inevitable that some features that we might be used to aren't available in the core library.\n\nOne such feature is the ability to grab the reference of a newly created or being removed DOM node. I found myself wanting this feature since I started using Hyperapp few weeks ago and this package is one possible answer for this requirement.\n\n## What do you get\n\nAbility to listen to two lifecycle events, `connected` and `disconnected` similar to `connectedCallback` and `disconnectedCallback` methods in [custom elements](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements).\n\n## Usage\n\nFull app lifecycle events coverage including app root node.\n\n```js\nimport * as hyperapp from 'https://unpkg.com/hyperapp?module'\nimport { timeout } from 'https://unpkg.com/@hyperapp/time?module'\nimport { lifecycle } from 'https://unpkg.com/hyperapp-lifecycle?module'\n\nconst { app, h } = lifecycle(hyperapp)\n\nconst Log = type =\u003e (state, evt) =\u003e console.log(`${type}:`, evt.target.tagName) || state\nconst RemoveWorld = state =\u003e ({ ...state, world: false })\n\nconst init = { world: true }\n\nconst view = state =\u003e\n  h('section', { onconnected: Log('Connected') },                    // Connected: SECTION\n    h('main', { onconnected: Log('Connected') },                     // Connected: MAIN\n      h('div', { onconnected: Log('Connected') },                    // Connected: DIV\n        h('span', { style: { color: 'green' } }, 'Hello'),\n        state.world \u0026\u0026                                               // Disconnected: SPAN\n        h('span', { ondisconnected: Log('Disconnected'), style: { color: 'blue' } }, ' World')\n      )\n    ),\n    h('p', null, h('i', null, 'open browser console to see events print out'))\n  )\n\nconst subscriptions = state =\u003e [timeout(RemoveWorld, { delay: 1000 })]\n\napp({ init, view, node, subscriptions })\n```\n\nNotice that, the custom event `target` is the DOM node that defined the event handler.\n\n## Lite mode\n\nLite mode features a supplementary function `l` that can be used as needed and where `h` remains unchanged. This gives more control on which nodes are allowed to fire lifecycle events for their children. The root node lifecycle events will be triggered as in full coverage mode.\n\nThe main point here to be aware of -as shown by the example below- is that, the use of `l` will ensure lifecycle events for children nodes and not for the node itself.\n\n```js\nimport * as hyperapp from 'https://unpkg.com/hyperapp?module'\nimport { timeout } from 'https://unpkg.com/@hyperapp/time?module'\nimport { lifecycle } from 'https://unpkg.com/hyperapp-lifecycle?module'\n\nconst { app, h, l } = lifecycle(hyperapp, /* lite mode */ true)\n\nconst Log = type =\u003e (state, evt) =\u003e console.log(`${type}:`, evt.target.tagName) || state\nconst RemoveWorld = state =\u003e ({ ...state, world: false })\n\nconst init = { world: true }\n\nconst view = state =\u003e\n  h('section', { onconnected: Log('Connected') },                    // Connected: SECTION\n    h('main', { onconnected: Log('Connected') },\n      l('div', { onconnected: Log('Connected') },\n        h('span', { style: { color: 'green' } }, 'Hello'),\n        state.world \u0026\u0026                                               // Disconnected: SPAN\n        h('span', { ondisconnected: Log('Disconnected'), style: { color: 'blue' } }, ' World')\n      )\n    ),\n    h('p', null, h('i', null, 'open browser console to see events print out'))\n  )\n\nconst subscriptions = state =\u003e [timeout(RemoveWorld, { delay: 1000 })]\n\napp({ init, view, node, subscriptions })\n ```\n\n## Superfine\n\nThe same works for the [Superfine](https://github.com/jorgebucaran/superfine) library, yay!\n\n```js\nimport * as superfine from 'https://unpkg.com/superfine?module'\nimport { timeout } from 'https://unpkg.com/@hyperapp/time?module'\nimport { lifecycle } from 'https://unpkg.com/hyperapp-lifecycle?module'\n\nconst { patch, h } = lifecycle(superfine)\n\nconst Log = type =\u003e evt =\u003e console.log(`${type}:`, evt.target.tagName)\nconst RemoveWorld = state =\u003e ({ ...state, world: false })\n\nconst init = { world: true }\n\nconst view = state =\u003e\n  h('section', { onconnected: Log('Connected') },                    // Connected: SECTION\n    h('main', { onconnected: Log('Connected') },                     // Connected: MAIN\n      h('div', { onconnected: Log('Connected') },                    // Connected: DIV\n        h('span', { style: 'color:green;' }, 'Hello'),\n        state.world \u0026\u0026                                               // Disconnected: SPAN\n        h('span', { ondisconnected: Log('Disconnected'), style: 'color:blue;' }, ' World')\n      )\n    ),\n    h('p', null, h('i', null, 'open browser console to see events print out'))\n  )\n\nconst app = state =\u003e patch(node, view(state))\n\napp(init)\n\nsetTimeout(()=\u003e app(RemoveWorld(init)), 1000)\n```\n\n## Credits\n\nThis package is based on the work of [Sergey Shpak](https://github.com/sergey-shpak) as can be viewed [here](https://gist.github.com/sergey-shpak/c1e0db3d52019eecb0b5717e8cbf00ad). The code performs black magic to hijack few of the node DOM methods in order to fire custom events. In addition to adding few extra features, the original code was slightly modified to ensure connected events are fired on `appendChild` and `insertBefore` calls.\n\n## Support\n\nNeed help or have a question? post a questions at [StackOverflow](https://stackoverflow.com/questions/tagged/hyperapp-lifecycle+web+semantics)\n\n*Please don't use the issue trackers for support/questions.*\n\n## Contributions\n\nHappy to accept external contributions to the project in the form of feedback, bug reports and even better - pull requests\n\n## Copyright and license\n\n[MIT license](http://opensource.org/licenses/mit-license.php)\nCopyright (c) Web Semantics, Inc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebsemantics%2Fhyperapp-lifecycle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebsemantics%2Fhyperapp-lifecycle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebsemantics%2Fhyperapp-lifecycle/lists"}