{"id":20929181,"url":"https://github.com/ayamflow/trickbag","last_synced_at":"2026-05-06T13:10:21.480Z","repository":{"id":29357262,"uuid":"32891630","full_name":"ayamflow/trickbag","owner":"ayamflow","description":"Add support for (stacked) mixins into any object.","archived":false,"fork":false,"pushed_at":"2015-03-28T09:34:22.000Z","size":120,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-19T22:03:44.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ayamflow.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}},"created_at":"2015-03-25T21:23:31.000Z","updated_at":"2015-03-28T09:34:20.000Z","dependencies_parsed_at":"2022-09-06T05:01:40.012Z","dependency_job_id":null,"html_url":"https://github.com/ayamflow/trickbag","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/ayamflow%2Ftrickbag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayamflow%2Ftrickbag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayamflow%2Ftrickbag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayamflow%2Ftrickbag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayamflow","download_url":"https://codeload.github.com/ayamflow/trickbag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243324270,"owners_count":20273099,"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-11-18T21:17:51.127Z","updated_at":"2025-12-28T13:20:10.881Z","avatar_url":"https://github.com/ayamflow.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"trickbag\n===\n\nAdd support for stacked mixins (separate behaviour) into any prototype.\nInspired by [Vue](http://vuejs.org) \u0026 [React](http://facebook.github.io/react/) mixins, and [Backbone Cocktail](https://github.com/onsi/cocktail).\n\nIt is useful to make your views/classes lighter and export common behavior in helpers. Some example use cases:\n\n* listening to the `resize` event and calling the appropriate method\n* listening to a mediator on object creation / unbinding the listener on object destruction\n* adding different behaviours on the same object hooks (`init`, `render` ...)\n* inheritance without `super`\n* ...\n\n## Installation\n\n`npm i trickbag --save`\n\n## Usage\n\n`trickbag(object, [mixins...]);`\n* `mixins` is an object (or an array of objects) containing methods; in other words, of mixins.\n* `object` is the object to apply these mixins to.\n\n## \"Stacks\"\n\nDifferent mixins used on the same object can have methods with identical names.\nWhen the mixins are processed, trickbag properly stack all methods with the same name by wrapping them in a parent method, preserving the call order.\nFor instance you can have an object with an `init` method. If your mixin also has the `init` method, it will be called after the object's one. That allows to easily plug behaviour on your custom classes lifecycle.\n\n## Example\n\n```js\n\nvar View = function(params) {\n  trickbag(this, params.mixins);\n};\n\nvar resizeMixin = {\n  init: function() {\n    this.onResize = this.onResize.bind(this);\n    window.addEventListener('resize', this.onResize);\n    console.log('Listening to resize')\n  },\n\n  onResize: function() {\n    this.width = window.innerWidth;\n    this.height = window.innerHeight;\n  },\n\n  destroy: function() {\n    window.removeEventListener('resize', this.onResize);\n  }\n};\n\nvar fooMixin = {\n  init: function() {\n    console.log('Foo foo');\n  }\n}\n\nvar v = new View({\n  mixins: [resizeMixin, fooMixin]\n});\n\nv.init(); // \"Listening to resize\", \"Foo foo\"\n\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayamflow%2Ftrickbag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayamflow%2Ftrickbag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayamflow%2Ftrickbag/lists"}