{"id":20284170,"url":"https://github.com/clebert/snugjs","last_synced_at":"2025-04-11T08:24:11.582Z","repository":{"id":53921144,"uuid":"521797072","full_name":"clebert/snugjs","owner":"clebert","description":"Create reactive web components using generator functions.","archived":false,"fork":false,"pushed_at":"2023-07-19T20:26:19.000Z","size":1997,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T05:43:46.395Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/clebert.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":"2022-08-05T23:07:36.000Z","updated_at":"2023-09-13T08:15:06.000Z","dependencies_parsed_at":"2024-10-19T12:34:44.421Z","dependency_job_id":"a3c6827d-14dd-4159-b135-f02af0249e5a","html_url":"https://github.com/clebert/snugjs","commit_stats":{"total_commits":43,"total_committers":1,"mean_commits":43.0,"dds":0.0,"last_synced_commit":"e5aa4cc79de6b50355b14e6281bccf14bbb3ad86"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fsnugjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fsnugjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fsnugjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fsnugjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clebert","download_url":"https://codeload.github.com/clebert/snugjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247581686,"owners_count":20961812,"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-11-14T14:18:35.679Z","updated_at":"2025-04-11T08:24:11.561Z","avatar_url":"https://github.com/clebert.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snugjs\n\n\u003e Create reactive web components using generator functions.\n\n## Installation\n\n```\nnpm install snugjs\n```\n\n## TodoMVC\n\nA work-in-progress implementation of [TodoMVC](http://todomvc.com) using\n`snugjs` and [`@snugjs/html`](https://github.com/clebert/snugjs-html) can be\nfound [here](https://github.com/clebert/snugjs-todomvc).\n\n## `\u003cCounter /\u003e` Element Factory\n\n```jsx\nimport {createElement} from '@snugjs/html';\nimport {CustomElement, createElementRef} from 'snugjs';\n\nexport const Counter = CustomElement.define(\n  'x-counter',\n  {initialCount: 'number?'},\n  function* ({next, signal}) {\n    const decrementButton = createElementRef('button');\n    const incrementButton = createElementRef('button');\n\n    let count = this.props.initialCount ?? 0;\n\n    decrementButton.element.addEventListener(\n      'click',\n      () =\u003e {\n        count -= 1;\n        next();\n      },\n      {signal},\n    );\n\n    incrementButton.element.addEventListener(\n      'click',\n      () =\u003e {\n        count += 1;\n        next();\n      },\n      {signal},\n    );\n\n    while (true) {\n      this.replaceChildren(\n        \u003cbutton key={decrementButton.key}\u003e-\u003c/button\u003e,\n        \u003cbutton key={incrementButton.key}\u003e+\u003c/button\u003e,\n        \u003cb\u003e{count}\u003c/b\u003e,\n      );\n\n      yield;\n    }\n  },\n);\n```\n\n```jsx\ndocument.body.appendChild(\u003cCounter initialCount={42} /\u003e);\n```\n\n```html\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003cx-counter initialCount=\"42\"\u003e\u003c/x-counter\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclebert%2Fsnugjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclebert%2Fsnugjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclebert%2Fsnugjs/lists"}