{"id":16111357,"url":"https://github.com/bripkens/mix.js","last_synced_at":"2025-03-18T09:31:03.228Z","repository":{"id":2821572,"uuid":"3823532","full_name":"bripkens/mix.js","owner":"bripkens","description":"Mixins with dependency resolution and private properties (without closures)","archived":false,"fork":false,"pushed_at":"2012-04-06T07:02:52.000Z","size":128,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-13T04:02:20.469Z","etag":null,"topics":[],"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/bripkens.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2012-03-25T10:17:01.000Z","updated_at":"2017-06-13T11:47:54.000Z","dependencies_parsed_at":"2022-08-26T06:21:15.629Z","dependency_job_id":null,"html_url":"https://github.com/bripkens/mix.js","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bripkens%2Fmix.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bripkens%2Fmix.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bripkens%2Fmix.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bripkens%2Fmix.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bripkens","download_url":"https://codeload.github.com/bripkens/mix.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244192555,"owners_count":20413546,"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":[],"created_at":"2024-10-09T19:41:55.928Z","updated_at":"2025-03-18T09:31:02.899Z","avatar_url":"https://github.com/bripkens.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mix.js\n\nmix.js is a tiny library to enable simple mixins and mixin dependency resolution\nin JavaScript. It focuses on unobtrusive and strong usage of mixins. It\noriginated in the [biographer project](http://code.google.com/p/biographer/)\nwhich requires many mixins with common dependencies, i.e., mixins which can be\nmixed and whose commonalities are taken into account at mixin generation time\n(not object instantiation time).\n\n# Terminology\n\n**Class**: JavaScript \"class\" as seen on the\n[Mozilla Developer Network](https://developer.mozilla.org/en/JavaScript/Reference/Operators/new).\n\n**Mixin**: A mix of one or more classes.\n\n\n# Project goals\n\n - Support for mixins in mixins, i.e., don't worry about mixin dependencies.\n - Private properties to avoid name clashes (without closures).\n - Possibility to call either functions as exposed through the object's public\n   API, class methods and methods exposed by other classes that are part of the\n   mixin.\n - Fast object instantiation.\n\n# Example\n\n``` javascript\n/*\n * We define a standard JavaScript \"class\" *Label*. It works just like you are\n * used to and the constructor can accept parameters through the *args*\n * parameter. Don't worry, mix.js makes sure that you are always getting\n * something as a parameter (at worst, you get an Object without\n * properties).\n */\nvar Label = function(args) {\n  /*\n   * These variables will be private and can't be overridden by other mixins\n   * or classes (at least, not by accident). No need to worry about name\n   * clashes with other mixins. The underscore is optional and has no\n   * effect on the visibility.\n   */\n  this._text = args.text || '';\n  this._canvas = args.canvas;\n};\n\n/*\n * All methods and properties added to the prototype will be available\n * through the instance's public API later on.\n */\nLabel.prototype.render = function() {\n  this._canvas.appendChild(document.createTextNode(this._text));\n};\n\nvar Rectangle = function(args) {\n  this._canvas = args.canvas;\n};\nRectangle.prototype.render = function() {\n  var element = document.createElement('div');\n  element.style.border = '1px solid black';\n  element.style.width = '100px';\n  element.style.height = '100px';\n\n  this._canvas.appendChild(element);\n}; \n\nvar RectangleWithLabel = function() {};\n\n/*\n * By default, methods will be \"overridden\". Since the Rectangle and Label\n * classes are independent from each other, we need to glue them together\n * in some way.\n * This example shows how you can access other classes' methods. Note the\n * *_id* property which will be auto-generated for you. This integer is\n * used to identify classes and is used for performance reasons.\n */\nRectangleWithLabel.prototype.render = function() {\n  this._instances[Label._id].render();\n  this._instances[Rectangle._id].render();\n};\n\n/*\n * This simple method call is enough to generate the mixin. You can even\n * mix a mixin with a class, class with a mixin and mixins with mixins.\n * Mix.js will take care of dependency resolution so that shared\n * classes are only instantiated once.\n * Check out the tests for more examples:\n * https://github.com/bripkens/mix.js/blob/master/test/spec/core.js\n */\nRectangleWithLabel = mix(Label, Rectangle, RectangleWithLabel);\n\nvar args = {\n  canvas: document.body,\n  text: '42 is the answer to your questions.'\n};\n\n/*\n * Create instance the way that you are used to!\n */\nvar instance = new RectangleWithLabel(args);\ninstance.render();\n\n/*\n * Result (in document body - fu GitHub, y u make this italic?):\n * 42 is the answer to your questions.\n * ┏━━━━━━━━━━━━━━━┓\n * ┃               ┃\n * ┃               ┃\n * ┃               ┃\n * ┃               ┃\n * ┗━━━━━━━━━━━━━━━┛\n */\n\n```\n\n\n# License (MIT)\nCopyright (c) 2012 Ben Ripkens\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbripkens%2Fmix.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbripkens%2Fmix.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbripkens%2Fmix.js/lists"}