{"id":13566901,"url":"https://github.com/fathyb/tolosa","last_synced_at":"2025-04-11T05:21:03.172Z","repository":{"id":75403567,"uuid":"125770243","full_name":"fathyb/tolosa","owner":"fathyb","description":"🚀✍️ An ambitious, ultra-fast, functional and declarative web framework (WIP)","archived":false,"fork":false,"pushed_at":"2018-03-18T21:42:29.000Z","size":111,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T02:06:03.394Z","etag":null,"topics":["babel","dom","jsx","rxjs","stream","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fathyb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-03-18T21:42:15.000Z","updated_at":"2022-11-13T20:51:52.000Z","dependencies_parsed_at":"2023-06-06T09:45:33.726Z","dependency_job_id":null,"html_url":"https://github.com/fathyb/tolosa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fathyb%2Ftolosa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fathyb%2Ftolosa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fathyb%2Ftolosa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fathyb%2Ftolosa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fathyb","download_url":"https://codeload.github.com/fathyb/tolosa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248346137,"owners_count":21088413,"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":["babel","dom","jsx","rxjs","stream","typescript"],"created_at":"2024-08-01T13:02:19.142Z","updated_at":"2025-04-11T05:21:03.151Z","avatar_url":"https://github.com/fathyb.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# tolosa\n\nA fast, functional, reactive and declarative web framework.\n\n\u003e Work in progress, see [Current status](#Current-status)\n\n# In a nutshell\n\n- 6KB, no dependencies\n- JSX with TypeScript and Flow support\n- Ultra-fast. Tolosa ranks top on most benchmarks\n- Simple and clean syntax. No class/object to implement. Just JSX\n- Lifecycle events\n- No need to import `h`. Create a hello world app in one line :\n  ```js\n  document.body.appendChild(\u003ch2\u003ehello world\u003c/h2\u003e)\n  ```\n- No virtual DOM. Updates are incremental, batched and non-redudant.\n- No state and predictible data-flow. Streams and/or monads are used instead, with support modules for :\n  - RxJS\n  - Most.js\n  - Make your own\n- And by design : two-way data binding, native lazy-loading and easy third party library integration : \n  ```jsx\n  const [foo, bar] = [new Emitter(), new Emitter()]\n  \u003ch2\u003e\n    {/* Lazy-loading using ES6 import */}\n    {import('./a-lazy-component')}\n    {/* Two-way data-binding, implicit or explicit */}\n    \u003cinput bind={foo}/\u003e\n    \u003cinput value={bar} onInput={bar}/\u003e\n    \u003cspan\u003efoo : {foo}, bar : {bar}\u003c/span\u003e\n    {\n      /* implement any external library, like jQuery */\n      $('\u003cspan\u003ehello from jQuery\u003c/span\u003e').get(0)\n    }\n  \u003c/h2\u003e\n  ```\n\nTolosa is heavily inspired by multiple frameworks :\n- Cycle.js for the functional and reactive principles\n- Surplus.js and incremental-dom for the DOM part\n- React for JSX\n\n# Installation\n\nTolosa is a set of packages published individually to npm.\nBabel or TypeScript is needed to compile your code. ([Why?](#))\n\n- Install the core : `yarn add @tolosa/core`\n- Install the plugin for your compiler :\n  - Babel : `yarn add @tolosa/transform-babel --dev`\n  - TypeScript : `yarn add @tolosa/transform-typescript --dev`\n- Install the support for your stream library (optional) : \n  - RxJS : `yarn add @tolosa/rxjs`\n  - Most.js : `yarn add @tolosa/most`\n\n# Usage\n\n## Update the UI\n\nYou can use multiple approach to update your UI.\n\n- Stream :\n  - Really fast, creates a direct connection between the source and the DOM node\n  - Makes the code more isolated, easier to test and scale\n- Imperative :\n  - Update and compare the DOM nodes in place each call\n  - May make the code simpler\n\n### Imperative oriented\n\nJSX elements are static in Tolosa. For example in the code below this is `true` : `render(0) === render(1)`.\n\nEach time `render` is called the DOM is compared in place and updates are batched. It can be compared to what `incremental-dom` is doing.\n\n```jsx\nconst initial = 0\nconst render = counter =\u003e\n    \u003cdiv\u003e\n        \u003cbutton onClick={() =\u003e render(counter + 1)}\u003eIncrement\u003c/button\u003e\n        \u003cbutton onClick={() =\u003e render(counter - 1)}\u003eDecrement\u003c/button\u003e\n        \u003ch2\u003eCounter : {counter}\u003c/h2\u003e\n    \u003c/div\u003e\n\ndocument.body.appendChild(render(initial))\n```\n\n### Stream oriented\n\n```jsx\n// Emitter is a RxJS Observable that can emit events\nimport {Emitter} from '@tolosa/rxjs'\nimport {merge} from 'rxjs'\n\nconst increment = new Emitter()\nconst decrement = new Emitter()\nconst initial = 0\n\n// create the counter stream\nconst counter =\n    merge(\n        // for each click on increment emit +1\n        increment.constant(+1),\n        // for each click on decrement emit -1\n        decrement.constant(-1)\n    )\n        // add the increment value to the counter\n        // with an initial value of 0\n        // .scan behaves like Array.reduce\n        .scan((acc, next) =\u003e acc + next, initial)\n\ndocument.body.appendChild(\n    \u003cdiv\u003e\n        \u003cbutton onClick={increment}\u003eIncrement\u003c/button\u003e\n        \u003cbutton onClick={decrement}\u003eDecrement\u003c/button\u003e\n        \u003ch2\u003eCounter : {counter}\u003c/h2\u003e\n    \u003c/div\u003e\n)\n```\n\n### Reducer using streams\n\n```jsx\n// Emitter is a RxJS Observable that can emit events\nimport {Emitter} from '@tolosa/rxjs'\nimport {merge} from 'rxjs'\n\nfunction reducer(state = 0, action) {\n    switch(action.type) {\n        case 'INCREMENT':\n            return state + 1\n        case 'DECREMENT':\n            return state - 1\n        default:\n            return state\n    }\n}\n\nconst increment = new Emitter()\nconst decrement = new Emitter()\n\n// create the counter stream\nconst counter = merge(\n    increment.constant({type: 'INCREMENT'}),\n    decrement.constant({type: 'DECREMENT'})\n).scan(reducer, reducer(0, {}))\n\ndocument.body.appendChild(\n    \u003cdiv\u003e\n        \u003cbutton onClick={increment}\u003eIncrement\u003c/button\u003e\n        \u003cbutton onClick={decrement}\u003eDecrement\u003c/button\u003e\n        \u003ch2\u003eCounter : {counter}\u003c/h2\u003e\n    \u003c/div\u003e\n)\n```\n\nSee `examples/`.\n\nLoad a remote resource :\n\n```jsx\nimport {fromPromise} from 'most'\n\ndocument.body.appendChild(\n    \u003cdiv\u003e\n        {\n            fromPromise(\n                fetch('/my-service').then(res =\u003e res.json())\n            ).startWith('Loading...')\n        }\n    \u003c/div\u003e\n)\n```\n\n# Current status\n\n- [x] Array support with `key`\n- [x] Stream support :\n  - [x] emit\n  - [x] observe\n  - [x] `style` observable property\n- [ ] Babel/Flow support\n- [ ] TypeScript support\n  - [x] General typings\n  - [x] Typed `Observable`/`Emitter` plugins\n  - [ ] JSX typings (currently set to any)\n- [ ] Fragments\n  - [x] Zero or one child\n  - [ ] More than one child\n- [ ] Stream libaries support\n  - [x] RxJS\n  - [x] Most.js\n  - [ ] xstream\n  - [ ] zen-observable\n- [ ] Rewrite the list comparison algorithm\n\n## How it internaly works\n\n### Compilation\n\n```jsx\nconst Component = () =\u003e\n    \u003cscope\u003e\n        \u003ch2\u003eIt's a component!\u003c/h2\u003e\n    \u003c/scope\u003e\n\nlet times = 0\nconst Element = () =\u003e\n\t\u003ch2\u003ethis element has been rendered {++times}\u003c/h2\u003e\n\n// Component() is not reused\nassert(Component() !== Component())\nassert(Component() !== Component())\n\n// Element() is reused\nassert(Element() == Element())\n\nconst element = \u003cdiv\u003e\n  \u003ch2 style={{color: 'red'}}\u003eSomething red\u003c/h2\u003e\n\u003c/div\u003e\n```\n\nGets compiled to (prettified) :\n\n```js\nimport { h } from \"@tolosa/core\";\n\nconst Component = () =\u003e {\n    var bag_1 = {};\n\n    return h(\n    //  tag,  bag,   id,  key,  props,\n        \"h2\", bag_1, \"2\", null, 0,\n    //  childs\n        [\"It's a component!\"]\n    );\n}\n\nassert(Component() !== Component());\n\nvar bag_0 = {};\n\nconst element = h(\n    // tag,   bag,   id,  key,  props\n       \"div\", bag_0, \"1\", null, 0,\n    // childs\n    [\n    //    tag,  bag,   id,  key,  props,          childs\n        h(\"h2\", bag_0, \"0\", null, {color: \"red\"}, [\"Something red\"])\n    ]\n);\n```\n\nThe bag is used to decide if we should reuse or create an element. In this case `bag_0` will be populated like this :\n```jsx\nbag_0 = {\n    '0': \u003c#HTMLHeadingElement/\u003e,\n    '1': \u003c#HTMLDivElement/\u003e,\n}\n```\n\n# Developement\n\nOnly `yarn` is supported.\n\n## Install deps\n\n`yarn`\n\n## Build\n\n- All : `yarn build`\n- Only a package, example with `transform/typescript` :\n  - `yarn build transform/typescript`\n  - or `yarn build packages/transform/typescript`\n\n## Test\n\nSource files are used, no building is needed.\n\n`yarn test`\n\n## Lint\n\n`yarn lint`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffathyb%2Ftolosa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffathyb%2Ftolosa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffathyb%2Ftolosa/lists"}