{"id":19382940,"url":"https://github.com/kenoxa/svelte-fragment-component","last_synced_at":"2025-04-23T20:32:34.859Z","repository":{"id":37941001,"uuid":"273770061","full_name":"kenoxa/svelte-fragment-component","owner":"kenoxa","description":"fragment component for svelte to simplify testing","archived":false,"fork":false,"pushed_at":"2023-01-23T23:08:34.000Z","size":481,"stargazers_count":4,"open_issues_count":15,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T20:11:30.444Z","etag":null,"topics":["javascript","svelte","testing","web"],"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/kenoxa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-06-20T19:16:45.000Z","updated_at":"2023-08-07T12:09:37.000Z","dependencies_parsed_at":"2023-02-13T04:35:19.476Z","dependency_job_id":null,"html_url":"https://github.com/kenoxa/svelte-fragment-component","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-fragment-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-fragment-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-fragment-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenoxa%2Fsvelte-fragment-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenoxa","download_url":"https://codeload.github.com/kenoxa/svelte-fragment-component/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250509881,"owners_count":21442515,"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":["javascript","svelte","testing","web"],"created_at":"2024-11-10T09:23:57.182Z","updated_at":"2025-04-23T20:32:33.447Z","avatar_url":"https://github.com/kenoxa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svelte-fragment-component\n\n\u003e A [svelte](https:/svelte.dev) component that renders its children with lifecycle hooks.\n\n[![License](https://badgen.net/npm/license/svelte-fragment-component)](https://github.com/kenoxa/svelte-fragment-component/blob/main/LICENSE)\n[![Latest Release](https://badgen.net/npm/v/svelte-fragment-component)](https://www.npmjs.com/package/svelte-fragment-component)\n[![View changelog](https://badgen.net/badge/%E2%80%8B/Explore%20Changelog/green?icon=awesome)](https://changelogs.xyz/svelte-fragment-component)\n\n[![CI](https://github.com/kenoxa/svelte-fragment-component/workflows/CI/badge.svg)](https://github.com/kenoxa/svelte-fragment-component/actions?query=branch%3Amain+workflow%3ACI)\n[![Coverage Status](https://badgen.net/coveralls/c/github/kenoxa/svelte-fragment-component/main)](https://coveralls.io/github/kenoxa/svelte-fragment-component?branch=main)\n[![PRs Welcome](https://badgen.net/badge/PRs/welcome/purple)](http://makeapullrequest.com)\n[![Conventional Commits](https://badgen.net/badge/Conventional%20Commits/1.0.0/cyan)](https://conventionalcommits.org)\n\n## What?\n\nDeclarative version of [Svelte](https://svelte.dev) component inspired by [reach-ui/component-component](https://reacttraining.com/reach-ui/component-component/).\n\n## Why?\n\nBecause sometimes (within tests) you want a lifecycle or some state but don't want to create a new component.\n\n_This is most likely only useful for libraries like [svelte-jsx](https://www.npmjs.com/package/svelte-jsx) or [svelte-htm](https://www.npmjs.com/package/svelte-htm)._\n\n## Installation\n\n```sh\nnpm install svelte-fragment-component\n```\n\nAnd then import it:\n\n```js\n// using es modules\nimport Fragment from 'svelte-fragment-component'\n\n// common.js\nconst Fragment = require('svelte-fragment-component')\n```\n\nOr use script tags and globals ([UNPKG](https://unpkg.com/svelte-fragment-component/) | [jsDelivr](https://cdn.jsdelivr.net/npm/svelte-fragment-component/)).\n\n```html\n\u003c!-- UNPKG --\u003e\n\u003cscript src=\"https://unpkg.com/svelte-fragment-component\"\u003e\u003c/script\u003e\n\n\u003c!-- jsDelivr --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/svelte-fragment-component\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  \u003c!-- And then grab it off the global like so: --\u003e\n  const Fragment = svelteFragment\n\u003c/script\u003e\n```\n\nHotlinking from unpkg: _(no build tool needed!)_\n\n```js\nimport Fragment from 'https://unpkg.com/svelte-fragment-component?module'\n```\n\n## Usage\n\n\u003e The examples below are using [svelte-jsx](https://www.npmjs.com/package/svelte-jsx) for the jsx syntax support.\n\n```js\nimport Fragment from 'svelte-fragment-component'\n\nconst Lifecycle = (\n  \u003cFragment\n    onCreate={() =\u003e {}}\n    onMount={() =\u003e {}}\n    beforeUpdate={() =\u003e {}}\n    afterUpdate={() =\u003e {}}\n    onDestroy={() =\u003e {}}\n  \u003e\n    some content\n  \u003c/Fragment\u003e\n)\n```\n\nThis allows to simplify testing of [context API](https://svelte.dev/docs#setContext):\n\n```js\nimport Fragment from 'svelte-fragment-component'\nimport { setContext } from 'svelte'\n\nconst Lifecycle = (\n  \u003cFragment\n    onCreate={() =\u003e {\n      setContext('some context key', theValue)\n    }}\n  \u003e\n    children can now access this context value\n  \u003c/Fragment\u003e\n)\n\n// or using the context property\nconst Lifecycle = (\n  \u003cFragment context={{ 'some context key': theValue }}\u003e\n    children can now access this context value\n  \u003c/Fragment\u003e\n)\n```\n\n## API\n\nThe component renders only the default slot children.\n\n### Properties\n\n\u003e All properties are optional.\n\n- `context`: an key-value object where each pair is passed to [setContext](https://svelte.dev/docs#setContext)\n\nExcept for `onCreate` these functions are passed to their corresponding svelte lifecycle method and have the same call signature `({ props }): void` where `props` are the `$$restProps`:\n\n- `onCreate`: called during component initialization\n- [onMount](https://svelte.dev/docs#onMount)\n- [beforeUpdate](https://svelte.dev/docs#beforeUpdate)\n- [afterUpdate](https://svelte.dev/docs#afterUpdate)\n- [onDestroy](https://svelte.dev/docs#onDestroy)\n\n## Related Projects\n\n- [svelte-jsx] - write svelte components using [jsx]\n- [svelte-htm] - [**H**yperscript **T**agged **M**arkup](https://www.npmjs.com/package/htm) for svelte; a [jsx]-like [syntax](https://www.npmjs.com/package/htm#syntax-like-jsx-but-also-lit) using [Tagged Templates]\n- [@testing-library/svelte](https://testing-library.com/docs/svelte-testing-library/intro) - helps to test UI components in a user-centric way\n\n## Support\n\nThis project is free and open-source, so if you think this project can help you or anyone else, you may [star it on GitHub](https://github.com/kenoxa/svelte-fragment-component). Feel free to [open an issue](https://github.com/kenoxa/svelte-fragment-component/issues) if you have any idea, question, or you've found a bug.\n\n## Contribute\n\nThanks for being willing to contribute!\n\n**Working on your first Pull Request?** You can learn how from this _free_ series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)\n\nWe are following the [Conventional Commits](https://www.conventionalcommits.org) convention.\n\n### Develop\n\n- `npm test`: Run test suite\n- `npm run build`: Generate bundles\n- `npm run lint`: Lints code\n\n## NPM Statistics\n\n[![NPM](https://nodei.co/npm/svelte-fragment-component.png)](https://nodei.co/npm/svelte-fragment-component/)\n\n## License\n\n`svelte-fragment-component` is open source software [licensed as MIT](https://github.com/kenoxa/svelte-fragment-component/blob/main/LICENSE).\n\n[tagged templates]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates\n[jsx]: https://reactjs.org/docs/introducing-jsx.html\n[svelte-jsx]: https://www.npmjs.com/package/svelte-jsx\n[svelte-hyperscript]: https://www.npmjs.com/package/svelte-hyperscript\n[svelte-htm]: https://www.npmjs.com/package/svelte-htm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenoxa%2Fsvelte-fragment-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenoxa%2Fsvelte-fragment-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenoxa%2Fsvelte-fragment-component/lists"}