{"id":13496262,"url":"https://github.com/gcanti/elm-ts","last_synced_at":"2025-04-05T05:03:20.587Z","repository":{"id":57222629,"uuid":"85850791","full_name":"gcanti/elm-ts","owner":"gcanti","description":"A porting to TypeScript featuring fp-ts, rxjs6 and React","archived":false,"fork":false,"pushed_at":"2022-10-08T03:22:56.000Z","size":836,"stargazers_count":300,"open_issues_count":4,"forks_count":12,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-03-29T04:03:57.528Z","etag":null,"topics":["elm-lang","fp-ts","functional-programming","react","rxjs6","typescript"],"latest_commit_sha":null,"homepage":"https://gcanti.github.io/elm-ts/","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/gcanti.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":"2017-03-22T16:24:21.000Z","updated_at":"2024-08-30T01:02:42.000Z","dependencies_parsed_at":"2022-08-29T01:50:49.736Z","dependency_job_id":null,"html_url":"https://github.com/gcanti/elm-ts","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Felm-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Felm-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Felm-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Felm-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gcanti","download_url":"https://codeload.github.com/gcanti/elm-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289409,"owners_count":20914464,"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":["elm-lang","fp-ts","functional-programming","react","rxjs6","typescript"],"created_at":"2024-07-31T19:01:44.729Z","updated_at":"2025-04-05T05:03:20.570Z","avatar_url":"https://github.com/gcanti.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Types"],"sub_categories":["IDE"],"readme":"# elm-ts\n\nA porting of [_The Elm Architecture_](https://guide.elm-lang.org/architecture/) to TypeScript featuring `fp-ts`, `RxJS` and `React`.\n\n## Installation\n\n```sh\nnpm i elm-ts fp-ts rxjs react\n```\n\nNote: `fp-ts`, `rxjs` and `react` are peer dependencies\n\n## Differences from Elm\n\n- no ports\n- `React` instead of `virtual-dom` (pluggable)\n- `Navigation` is based on [history](https://github.com/ReactTraining/history)\n\n## React\n\n```ts\nimport * as React from 'elm-ts/lib/React'\nimport { render } from 'react-dom'\nimport * as component from './examples/Counter'\n\nconst main = React.program(component.init, component.update, component.view)\n\nReact.run(main, dom =\u003e render(dom, document.getElementById('app')!))\n```\n\n## How to derive decoders from [io-ts](https://github.com/gcanti/io-ts) codecs\n\n```ts\nimport * as t from 'io-ts'\nimport { failure } from 'io-ts/lib/PathReporter'\n\nfunction fromCodec\u003cA\u003e(codec: t.Decoder\u003cunknown, A\u003e): Decoder\u003cA\u003e {\n  return flow(\n    codec.decode,\n    E.mapLeft(errors =\u003e failure(errors).join('\\n'))\n  )\n}\n```\n\n## Enable debugger in development mode\n\nFor `Html` (and its specializations) programs:\n\n```ts\nimport { programWithDebugger } from 'elm-ts/lib/Debug/Html'\nimport * as React from 'elm-ts/lib/React'\nimport { render } from 'react-dom'\nimport * as component from './examples/Counter'\n\nconst program = process.env.NODE_ENV === 'production' ? React.program : programWithDebugger\n\nconst main = program(component.init, component.update, component.view)\n\nReact.run(main, dom =\u003e render(dom, document.getElementById('app')!))\n```\n\nFor `Navigation` (and its specializations) programs:\n\n```ts\nimport { programWithDebuggerWithFlags } from 'elm-ts/lib/Debug/Navigation'\nimport * as Navigation from 'elm-ts/lib/Navigation'\nimport * as React from 'elm-ts/lib/React'\nimport { render } from 'react-dom'\nimport * as component from './examples/Navigation'\n\nconst program = process.env.NODE_ENV === 'production' ? Navigation.programWithFlags : programWithDebuggerWithFlags\n\nconst main = program(component.locationToMsg, component.init, component.update, component.view)\n\nReact.run(main(component.flags), dom =\u003e render(dom, document.getElementById('app')!))\n```\n\n## Stop the application\n\nIf you need to stop the application for any reason, you can use the `withStop` combinator:\n\n```ts\nimport { withStop } from 'elm-ts/lib/Html'\nimport * as React from 'elm-ts/lib/React'\nimport { render } from 'react-dom'\nimport { fromEvent } from 'rxjs'\nimport * as component from './examples/Counter'\n\nconst stopSignal$ = fromEvent(document.getElementById('stop-btn'), 'click')\n\nconst program = React.program(component.init, component.update, component.view)\n\nconst main = withStop(stopSignal$)(program)\n\nReact.run(main, dom =\u003e render(dom, document.getElementById('app')!))\n```\n\nThe combinator takes a `Program` and stops consuming it when the provided `Observable` emits a value.\n\nIn case you want to enable the debugger, you have to use some specific functions from the `Debug` sub-module:\n\n```ts\n// instead of `programWithDebuggerWithFlags`\nimport { programWithDebuggerWithFlagsWithStop } from 'elm-ts/lib/Debug/Navigation'\nimport { withStop } from 'elm-ts/lib/Html'\nimport * as Navigation from 'elm-ts/lib/Navigation'\nimport * as React from 'elm-ts/lib/React'\nimport { render } from 'react-dom'\nimport * as component from './examples/Navigation'\n\nconst stopSignal$ = fromEvent(document.getElementById('stop-btn'), 'click')\n\nconst program =\n  process.env.NODE_ENV === 'production'\n    ? Navigation.programWithFlags\n    : programWithDebuggerWithFlagsWithStop(stopSignal$)\n\nconst main = withStop(stopSignal$)(program(component.locationToMsg, component.init, component.update, component.view))\n\nReact.run(main(component.flags), dom =\u003e render(dom, document.getElementById('app')!))\n```\n\n## Examples\n\n- [Counter](examples/Counter.tsx)\n- [Labeled Checkboxes (with a sprinkle of functional optics)](examples/LabeledCheckboxes.tsx)\n- [Task, Time and Option](examples/Task.tsx)\n- [Http and Either](examples/Http.tsx)\n- [Navigation](examples/Navigation.tsx)\n- [Compose Modules](examples/ComposeModules/index.tsx)\n\n## Documentation\n\n- [API Reference](https://gcanti.github.io/elm-ts)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgcanti%2Felm-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgcanti%2Felm-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgcanti%2Felm-ts/lists"}