{"id":15474822,"url":"https://github.com/typescript-tea/core","last_synced_at":"2025-04-22T14:09:15.172Z","repository":{"id":42225491,"uuid":"236338812","full_name":"typescript-tea/core","owner":"typescript-tea","description":"The Elm Architecture for typescript","archived":false,"fork":false,"pushed_at":"2025-02-05T13:34:41.000Z","size":561,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T14:09:05.939Z","etag":null,"topics":["elm","elm-architecture","tea","typescript"],"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/typescript-tea.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-01-26T16:20:07.000Z","updated_at":"2025-04-11T09:49:07.000Z","dependencies_parsed_at":"2022-09-13T17:43:01.500Z","dependency_job_id":null,"html_url":"https://github.com/typescript-tea/core","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typescript-tea%2Fcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typescript-tea%2Fcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typescript-tea%2Fcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typescript-tea%2Fcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typescript-tea","download_url":"https://codeload.github.com/typescript-tea/core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250255697,"owners_count":21400410,"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","elm-architecture","tea","typescript"],"created_at":"2024-10-02T03:04:48.295Z","updated_at":"2025-04-22T14:09:15.141Z","avatar_url":"https://github.com/typescript-tea.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @typescript-tea/core\n\n[![npm version][version-image]][version-url]\n[![build][build-image]][build-url]\n[![Coverage Status][codecov-image]][codecov-url]\n[![code style: prettier][prettier-image]][prettier-url]\n[![MIT license][license-image]][license-url]\n\nThe Elm Architecture for typescript\n\n## Introduction\n\nThis is an implementation of The Elm Architecture (TEA) for typescript.\n\nNote: TEA has managed effects, meaning that things like HTTP requests or writing to disk are all treated as data in TEA. When this data is given to an Effect Manager, it can do some \"query optimization\" before actually performing the effect. Your application should consist of pure functions only and all effects should be handled in Effect Managers outside your application.\n\nTEA has two kinds of managed effects: commands and subscriptions.\n\n## How to use\n\n```\nyarn add @typescript-tea/core\n```\n\n## Documentation\n\nPlease see the [documentation site](https://typescript-tea.github.io/core).\n\n## Example\n\nThis is the usual counter app example using the react as view library. It is also available in [this repo](https://github.com/typescript-tea/simple-counter-example).\n\n```ts\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { exhaustiveCheck } from \"ts-exhaustive-check\";\nimport { Dispatch, Program } from \"@typescript-tea/core\";\n\n// -- STATE\n\ntype State = number;\nconst init = (): readonly [State] =\u003e [0];\n\n// -- UPDATE\n\ntype Action = { type: \"Increment\" } | { type: \"Decrement\" };\n\nfunction update(action: Action, state: State): readonly [State] {\n  switch (action.type) {\n    case \"Increment\":\n      return [state + 1];\n    case \"Decrement\":\n      return [state - 1];\n    default:\n      return exhaustiveCheck(action, true);\n  }\n}\n\n// -- VIEW\n\nconst view = ({ dispatch, state }: { readonly dispatch: Dispatch\u003cAction\u003e; readonly state: State }) =\u003e (\n  \u003cdiv\u003e\n    \u003cbutton onClick={() =\u003e dispatch({ type: \"Decrement\" })}\u003e-\u003c/button\u003e\n    \u003cdiv\u003e{state}\u003c/div\u003e\n    \u003cbutton onClick={() =\u003e dispatch({ type: \"Increment\" })}\u003e+\u003c/button\u003e\n  \u003c/div\u003e\n);\n\n// -- PROGRAM\n\nconst program: Program\u003cState, Action, JSX.Element\u003e = {\n  init,\n  update,\n  view,\n};\n\n// -- RUN\n\nconst app = document.getElementById(\"app\");\nconst render = (view: JSX.Element) =\u003e ReactDOM.render(view, app);\nProgram.run(program, render);\n```\n\n## Differences from TEA in Elm\n\nThere are some naming differences from TEA in Elm:\n\n- `Msg` was renamed to `Action`\n- `Model` was renamed to `State`\n\nElm is a pure language with strict guarantees and the Effect Managers are part of kernel in Elm and you cannot (for good [reasons](https://groups.google.com/forum/#!msg/elm-dev/1JW6wknkDIo/H9ZnS71BCAAJ)) write your own Effect Managers in Elm. Typescript is an impure lanauge without any guarantees so it (probably) does not make sense to have this restriction. Therefore in typescript-tea it is possible to write your own Effect Manager to do whatever you want.\n\nIt does not have a built-in view library, instead it is possible to integrate with existing view libraries like React.\n\n## How to import\n\n### Whole module from the root\n\nThis package (and others in `@typescript-tea` organization) exports only `function`s and `type`s grouped into modules. You can import a module from the root of the package in the following way:\n\n```ts\nimport { ModuleName1, ModuleName2 } from \"@typescript-tea/package-name\";\n```\n\nFor example:\n\n```ts\nimport { Result } from \"@typescript-tea/core\";\n\nconst result = Result.Ok(\"It is OK\");\n```\n\n### Unprefixed named imports from the module file\n\nIf you don't want to prefix with `ModuleName` you can also use named imports directly from the module file:\n\n```ts\nimport { function1, function2 } from \"@typescript-tea/package-name/module-name\";\n```\n\nFor example:\n\n```ts\nimport { Ok } from \"@typescript-tea/core/result\";\n\nconst result = Ok(\"It is OK\");\n```\n\n### Modules that export a single type\n\nA common pattern is to have a module that exports a single type with the same name as the module. For example the `Result` module does this, it exports the `Result` type, some constructor functions that create a `Result` type, and some utility funcitons that operate on or return a `Result` type. In these cases it can become annoying to prefix the type with the module name, like `Result.Result`. Consider the following example. Note that this is **not** how it is done for modules with single type exports in typescript-tea, it is just to illustrate how it would be done normally:\n\n```ts\nimport { Result } from \"@typescript-tea/core\";\n\nfunction itsOk(): Result.Result\u003cstring, string\u003e {\n  const ok: Result.Result\u003cstring, string\u003e = Result.Ok(\"It is OK\");\n  const err: Result.Result\u003cstring, string\u003e = Result.Ok(\"It is not OK\");\n  return ok;\n}\n```\n\nTo avoid having to write `Result.Result` in these cases, the `Result` module uses a trick so that both the module name and the type can be named simply `Result`. So the code above will become this (notice use of `Result` for the type annotations instead of `Result.Result`):\n\n```ts\nimport { Result } from \"@typescript-tea/core\";\n\nfunction itsOk(): Result\u003cstring, string\u003e {\n  const ok: Result\u003cstring, string\u003e = Result.Ok(\"It is OK\");\n  const err: Result\u003cstring, string\u003e = Result.Ok(\"It is not OK\");\n  return ok;\n}\n```\n\nHow can this work? Well, the index file in the package does this to make it work:\n\n```ts\nimport * as ResultNs from \"./result\";\n\nexport const Result = ResultNs;\nexport type Result\u003cTError, TValue\u003e = ResultNs.Result\u003cTError, TValue\u003e;\n```\n\nI think it is somehow related to [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) in typescript :-).\n\nPlease note that this only work for modules that export a single type. If two types are exported it is not possible to use this shortcut because the exported `const` will not contain any types.\n\n## How to develop\n\nNode version \u003e=12.6.0 is needed for development.\n\nTo execute the tests run `yarn test`.\n\n## How to publish\n\n```\nyarn version --patch\nyarn version --minor\nyarn version --major\n```\n\n[version-image]: https://img.shields.io/npm/v/@typescript-tea/core.svg?style=flat\n[version-url]: https://www.npmjs.com/package/@typescript-tea/core\n[build-image]: https://github.com/typescript-tea/core/workflows/Build/badge.svg\n[build-url]: https://github.com/typescript-tea/core/actions?query=workflow%3ABuild+branch%3Amaster\n[codecov-image]: https://codecov.io/gh/typescript-tea/core/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/typescript-tea/core\n[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat\n[prettier-url]: https://github.com/prettier/prettier\n[license-image]: https://img.shields.io/github/license/typescript-tea/core.svg?style=flat\n[license-url]: https://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypescript-tea%2Fcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypescript-tea%2Fcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypescript-tea%2Fcore/lists"}