{"id":13793531,"url":"https://github.com/davidjamesstone/hyperapp-customelements","last_synced_at":"2025-04-15T18:30:46.244Z","repository":{"id":69183782,"uuid":"123346748","full_name":"davidjamesstone/hyperapp-customelements","owner":"davidjamesstone","description":"W3C Web Components Custom Elements for hyperapp","archived":false,"fork":false,"pushed_at":"2018-03-17T21:55:17.000Z","size":247,"stargazers_count":17,"open_issues_count":2,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T00:34:08.495Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://davidjamesstone.github.io/hyperapp-customelements/","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/davidjamesstone.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-28T21:51:29.000Z","updated_at":"2020-11-15T23:10:13.000Z","dependencies_parsed_at":"2023-07-23T20:45:07.173Z","dependency_job_id":null,"html_url":"https://github.com/davidjamesstone/hyperapp-customelements","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"6fe7b95c7c7b6d166e0c5873c4a9377f3825d39f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidjamesstone%2Fhyperapp-customelements","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidjamesstone%2Fhyperapp-customelements/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidjamesstone%2Fhyperapp-customelements/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidjamesstone%2Fhyperapp-customelements/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidjamesstone","download_url":"https://codeload.github.com/davidjamesstone/hyperapp-customelements/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249128893,"owners_count":21217237,"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":[],"created_at":"2024-08-03T23:00:23.549Z","updated_at":"2025-04-15T18:30:45.892Z","avatar_url":"https://github.com/davidjamesstone.png","language":"JavaScript","funding_links":[],"categories":["Utilities V1"],"sub_categories":[],"readme":"# hyperapp-customelements\n\n`hyperapp-customelements` is a tiny (3KB) Web Components [Custom Elements library](#custom-elements) based on `hyperapp`.\n\nDefine Custom Elements that:\n\n- work in all evergreen browsers and IE10.\n- are based on [hyperapp](https://github.com/hyperapp/hyperapp) so you get\n  - a beautifully simple API\n  - a functional paradigm\n  - immutable state data\n  - Virtual DOM updates\n- provide a solid migration path to Custom Elements V1\n\nSee it in action [here](https://davidjamesstone.github.io/hyperapp-customelements/)\n\n```js\nconst define = require('hyperapp-customelements')\n\nconst MyElement = define({\n  // Required\n  name: 'my-element',\n  view () {\n    // Any `h()` returning function including JSX or a transformed `hyperviews` template\n  },\n\n  // Optional\n  state: {\n    // Initial hyperapp state\n  },\n  actions: {\n    // Hyperapp actions\n  },\n  constructor () {\n    // Wired actions are now available as `this.actions`\n  },\n  // Attributes to observe.\n  // Each item in the array must be a string or an object.\n  // Use an object to provide a conversion function.\n  // The function is used to convert the value from a string when reflecting to state\n  // E.g ['title', { max: Number }, { show: Boolean }, { custom: (value) =\u003e {...} }, 'another']\n  observedAttributes: Array,\n  attributeChangedCallback (name, oldValue, newValue) {\n    // Invoked when an observed attribute changes.\n    // Attribute changes are reflected to state by default.\n    // It's therefore not always necessary to provide this function.\n    // Set `mapAttrsToState` to `false` to update state manually.\n  },\n  connectedCallback () {\n    // Invoked when the element is inserted into the document\n  },\n  disconnectedCallback () {\n    // Invoked when the element is removed from the document\n  },\n  //...any other properties/methods are added to the element prototype\n})\n```\n\nThen use declaratively\n\n```html\n\u003cmy-element\u003e\u003c/my-element\u003e\n```\n\nor programmatically\n\n```js\nconst myElement = new MyElement()\ndocument.body.appendChild(myElement)\n```\n\n## Example\n\n```js\nconst define = require('hyperapp-customelements')\n\ndefine({\n  name: 'x-counter',\n  state: {\n    counter: 0\n  },\n  actions: {\n    down: value =\u003e state =\u003e ({ count: state.count - value }),\n    up: value =\u003e state =\u003e ({ count: state.count + value })\n  },\n  view: (state, actions) =\u003e (\n    \u003cdiv\u003e\n      \u003ch1\u003e{state.count}\u003c/h1\u003e\n      \u003cbutton onclick={() =\u003e actions.down(1)} disabled={state.count \u003c= 0}\u003eー\u003c/button\u003e\n      \u003cbutton onclick={() =\u003e actions.up(1)} disabled={state.count \u003e= state.max}\u003e＋\u003c/button\u003e\n    \u003c/div\u003e\n  ),\n  observedAttributes: [{ max: Number }]\n})\n```\n\n```html\n\u003cx-counter max=\"10\"\u003e\u003c/x-counter\u003e\n```\n# Notes\n\nYou may notice that the API looks like Custom Elements V1, however the decision was taken to \ninitially [target Custom Elements V0](https://github.com/WebReflection/ce-v0) but with a V1 flavour so, when V1 is widely supported, the upgrade will be simple. See [this article](https://medium.com/@WebReflection/a-custom-elements-v0-grampafill-dc1319420e9b) for more information. Huge thanks to [Andrea Giammarchi](https://github.com/WebReflection) for all his work in this area.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidjamesstone%2Fhyperapp-customelements","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidjamesstone%2Fhyperapp-customelements","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidjamesstone%2Fhyperapp-customelements/lists"}