{"id":13394712,"url":"https://github.com/developit/decko","last_synced_at":"2025-05-14T20:09:05.230Z","repository":{"id":57745310,"uuid":"41275115","full_name":"developit/decko","owner":"developit","description":":dash: The 3 most useful ES7 decorators: bind, debounce and memoize","archived":false,"fork":false,"pushed_at":"2018-10-12T22:33:20.000Z","size":51,"stargazers_count":1037,"open_issues_count":6,"forks_count":35,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-13T22:26:27.959Z","etag":null,"topics":["debounce","decorators","memoization","memoize","throttle-calls"],"latest_commit_sha":null,"homepage":"https://developit.github.io/decko/","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/developit.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":"2015-08-24T01:30:40.000Z","updated_at":"2025-03-26T05:53:32.000Z","dependencies_parsed_at":"2022-08-30T14:20:46.318Z","dependency_job_id":null,"html_url":"https://github.com/developit/decko","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdecko","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdecko/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdecko/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdecko/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developit","download_url":"https://codeload.github.com/developit/decko/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254219373,"owners_count":22034397,"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":["debounce","decorators","memoization","memoize","throttle-calls"],"created_at":"2024-07-30T17:01:29.069Z","updated_at":"2025-05-14T20:09:05.207Z","avatar_url":"https://github.com/developit.png","language":"JavaScript","readme":"# decko [![NPM Version](https://img.shields.io/npm/v/decko.svg?style=flat)](https://npmjs.com/package/decko) [![Build Status](https://travis-ci.org/developit/decko.svg?branch=master)](https://travis-ci.org/developit/decko)\n\nA concise implementation of the three most useful [decorators](https://github.com/wycats/javascript-decorators):\n\n- `@bind`: make the value of `this` constant within a method\n- `@debounce`: throttle calls to a method\n- `@memoize`: cache return values based on arguments\n\nDecorators help simplify code by replacing the noise of common patterns with declarative annotations.\nConversely, decorators can also be overused and create obscurity.\nDecko establishes 3 standard decorators that are immediately recognizable, so you can avoid creating decorators in your own codebase.\n\n\u003e 💡 **Tip:** decko is particularly well-suited to [**Preact Classful Components**](https://github.com/developit/preact).\n\u003e\n\u003e 💫 **Note:**\n\u003e - For Babel 6+, be sure to install [babel-plugin-transform-decorators-legacy](https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy).\n\u003e - For Typescript, be sure to enable `{\"experimentalDecorators\": true}` in your tsconfig.json.\n\n## Installation\n\nAvailable on [npm](https://npmjs.com/package/decko):\n\n```sh\nnpm i -S decko\n```\n\n\n## Usage\n\nEach decorator method is available as a named import.\n\n```js\nimport { bind, memoize, debounce } from 'decko';\n```\n\n\n### `@bind`\n\n```js\nclass Example {\n\t@bind\n\tfoo() {\n\t\t// the value of `this` is always the object from which foo() was referenced.\n\t\treturn this;\n\t}\n}\n\nlet e = new Example();\nassert.equal(e.foo.call(null), e);\n```\n\n\n\n### `@memoize`\n\n\u003e Cache values returned from the decorated function.\n\u003e Uses the first argument as a cache key.\n\u003e _Cache keys are always converted to strings._\n\u003e\n\u003e ##### Options:\n\u003e\n\u003e `caseSensitive: false` - _Makes cache keys case-insensitive_\n\u003e\n\u003e `cache: {}` - _Presupply cache storage, for seeding or sharing entries_\n\n```js\nclass Example {\n\t@memoize\n\texpensive(key) {\n\t\tlet start = Date.now();\n\t\twhile (Date.now()-start \u003c 500) key++;\n\t\treturn key;\n\t}\n}\n\nlet e = new Example();\n\n// this takes 500ms\nlet one = e.expensive(1);\n\n// this takes 0ms\nlet two = e.expensive(1);\n\n// this takes 500ms\nlet three = e.expensive(2);\n```\n\n\n\n### `@debounce`\n\n\u003e Throttle calls to the decorated function. To debounce means \"call this at most once per N ms\".\n\u003e All outward function calls get collated into a single inward call, and only the latest (most recent) arguments as passed on to the debounced function.\n\u003e\n\u003e ##### Options:\n\u003e\n\u003e `delay: 0` - _The number of milliseconds to buffer calls for._\n\n```js\nclass Example {\n\t@debounce\n\tfoo() {\n\t\treturn this;\n\t}\n}\n\nlet e = new Example();\n\n// this will only call foo() once:\nfor (let i=1000; i--) e.foo();\n```\n\n\n---\n\nLicense\n-------\n\nMIT\n","funding_links":[],"categories":["JavaScript","Utilities"],"sub_categories":["Miscellaneous"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopit%2Fdecko","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevelopit%2Fdecko","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopit%2Fdecko/lists"}