{"id":19014291,"url":"https://github.com/elemental-mind/fusium","last_synced_at":"2025-11-11T01:30:54.705Z","repository":{"id":227616967,"uuid":"731814141","full_name":"elemental-mind/fusium","owner":"elemental-mind","description":"Supercharged composition in TypeScript","archived":false,"fork":false,"pushed_at":"2024-04-30T21:50:35.000Z","size":73,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-02T06:34:21.190Z","etag":null,"topics":["composition","composition-api","mixin","mixins","multiple-inheritance","traits"],"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/elemental-mind.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":"2023-12-15T00:11:01.000Z","updated_at":"2024-12-10T18:20:41.000Z","dependencies_parsed_at":"2024-03-14T09:39:50.354Z","dependency_job_id":"ead2f58f-a611-41ed-9665-1835b0706cbb","html_url":"https://github.com/elemental-mind/fusium","commit_stats":null,"previous_names":["elemental-mind/fusium"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elemental-mind%2Ffusium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elemental-mind%2Ffusium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elemental-mind%2Ffusium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elemental-mind%2Ffusium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elemental-mind","download_url":"https://codeload.github.com/elemental-mind/fusium/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240052975,"owners_count":19740604,"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":["composition","composition-api","mixin","mixins","multiple-inheritance","traits"],"created_at":"2024-11-08T19:28:45.230Z","updated_at":"2025-11-11T01:30:54.665Z","avatar_url":"https://github.com/elemental-mind.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fusium\n\nClass based composition/Mix-Ins in TS \u0026 JS made intuitive, elegant and powerful. If you have missed multiple inheritance in TS, you have missed this library.\n\nWrite Classes that describe `Traits` of objects and compose those traits to form new, more complex types. If you don't like the official Mix-In syntax and its constraints, this library offers a viable (but experimental) alternative.\n\n## State of the project\n\nThis project is experimental and is only roughly tested on V8 based platforms so far.\n\n## Introduction\n\nIn object-oriented programming, composition is a design principle that allows for the creation of complex types by combining simpler, more focused types. Unlike inheritance, which defines a class in terms of another class, composition defines a class as containing instances of other classes. This approach offers several benefits:\n\n- Modularity: By breaking down functionality into smaller, reusable components, code becomes more organized and easier to manage.\n- Flexibility: Components can be easily replaced or updated without affecting the overall system.  \n- Maintainability: Smaller, well-defined components are easier to understand, test, and debug.\n- Avoidance of Inheritance Pitfalls: Composition avoids issues like the fragile base class problem and deep inheritance hierarchies that can make code brittle and difficult to refactor.\n\nThe Fusium Composition Library leverages TypeScript's advanced type system together with JS proxies to provide a powerful and type-safe way to compose classes. It allows developers to fuse multiple classes into a single one, combining their behaviors and properties without the drawbacks of traditional inheritance.\n\n## Core Concepts\n\nThis library is tiny and builds on top of three main ideas:\n- **Composable/Trait**: A `Trait` or `Composable` (they are equivalent, but just differently named to aid semantics in certain contexts) is a group of functionality and data that can be composed together. In practice this is bundled together as an ES6-class and can be either used standalone if sufficient or in a `Fusion`. `Traits` may for example be `deletable`, `writable` etc.\n- **Fusions**: A `Fusion` is the composition or combination of multiple `Traits` into either a more complex `Trait` or an `Object` that exhibits these `Traits`. A super-trait like \"streamable\" may, for example, be composed of `Traits` like `asynchronous` and `cancellable` and thus would be a `Fusion` of the two. An `Object` exhibiting these traits may for example be a `Document` that is a `Fusion` of the `writable` and `deletable` Traits.\n- **Co-Traits**: Sometimes certain `Traits` need to make assumptions about their \"environment\". Looking at an example: `UIElement` for instance could be an `Object` that may be `draggable`. This implies, however, that the element is `movable`, and thus has a position on screen - and the `draggable` trait will try to interact with that position in a way. It thus requires the traits `positioned`, `movable` and `pointable` to be other traits of an object that wants to have the `draggable` trait. `positioned`, `pointable` and `moveable` would be `Co-Traits` of `draggable`. `draggable` assumes these traits and `UIElement` must be a `Fusion` of at least these three traits together.\n\n## Installation\n\nFusium is just an npm install away:\n\n  ```\n  npm install fusium-js\n  ```\n\n## Usage Examples\n\nHere's a simple pseudo-code example concretizing the concepts above to compose a `UIElement`:\n\n```typescript\nimport { Trait, CoTraits, FusionOf } from \"fusium-js\";\n\n// Define the UIElement as a Fusion/Composition of the traits\n// Not that UIElement does not contain any logic for wiring traits together as the traits\n// already know their environment and how to interact with each other through their defined \"Co-Traits\"\nclass UIElement extends FusionOf(Draggable, Movable, Pointable, Positioned) {\n    constructor()\n    {\n        this.onPositionChanged(() =\u003e { /*...reRendering logic...*/});\n    }\n}\n\n// Define the individual traits as classes that extend from Trait\nclass Positioned extends Trait \n{\n  protected x: number;\n  protected y: number;\n  public onPositionChanged = new EventEmitter();\n\n  setPosition(x, y) {...}\n}\n\n// This trait assumes and works with the x and y coordinates from the Co-Trait `Positioned`\nclass Movable extends CoTraits(Positioned)   \n{\n  move(dx: number, dy: number) {\n    this.setPosition(this.x + dx, this.y + dy);\n  }\n}\n\n// Note that in order to be Composable, a class (or the base end of its inheritance chain) needs to derive from `Composable` or `Trait`\nclass Pointable extends Trait   \n{\n  constructor()\n  {\n    environment.trackPointer(this)\n  }\n\n    onPointerPressed = new EventEmitter();\n    onPointerReleased = new EventEmitter();\n    onPointerMove = new EventEmitter();\n}\n\n// Note that the CoTraits-Function serves very little purpose on JS level (it's a typed Placeholder for `Trait`), but rather helps with type-safety on TS level\n// Only the FusionOf-Function actually composes functionality on the JS level\nclass Draggable extends CoTraits(Pointable, Movable) \n{\n    registerListeners()\n    {\n        this.onPointerPressed(() =\u003e this.onPointerMove(handlePressedAndMoved));\n    }\n\n    handlePressedAndMoved(dx, dy)\n    {\n        this.move(dx, dy);\n    }\n}\n```\n\n## Performance\n\nThis library should have little effect on runtime performance, except from marginal slow-down in object definition (as the types are composed once you call the \"FusionOf\"-Function) and object instantiation (single-line constructor-proxy). The resultant classes should still be optimizable by V8 etc. as the prototype chain remains flat and static once \"FusionOf\" was called, which normally happens while \"parsing\"/initially running a module.\n\n## Contribution\n\nFor now this project is experimental - thus your feedback and input and thoughts are highly appreciated.\n\n## License\n\nFusium is open-source software licensed under the MIT License. This means you're free to use, modify, and distribute the library, provided you include the original license and copyright notice in any copies or substantial portions of the software.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felemental-mind%2Ffusium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felemental-mind%2Ffusium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felemental-mind%2Ffusium/lists"}