{"id":18563138,"url":"https://github.com/compulim/memoize-one-with-dispose","last_synced_at":"2025-04-10T03:32:34.991Z","repository":{"id":33506576,"uuid":"158994433","full_name":"compulim/memoize-one-with-dispose","owner":"compulim","description":"A memoization function with cache of one and disposing function","archived":false,"fork":false,"pushed_at":"2022-12-08T06:16:13.000Z","size":1203,"stargazers_count":3,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T16:02:53.876Z","etag":null,"topics":["memoize"],"latest_commit_sha":null,"homepage":null,"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/compulim.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":"2018-11-25T03:29:23.000Z","updated_at":"2020-08-10T01:23:00.000Z","dependencies_parsed_at":"2023-01-15T01:12:57.873Z","dependency_job_id":null,"html_url":"https://github.com/compulim/memoize-one-with-dispose","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/compulim%2Fmemoize-one-with-dispose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Fmemoize-one-with-dispose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Fmemoize-one-with-dispose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Fmemoize-one-with-dispose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compulim","download_url":"https://codeload.github.com/compulim/memoize-one-with-dispose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111975,"owners_count":21049578,"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":["memoize"],"created_at":"2024-11-06T22:11:54.642Z","updated_at":"2025-04-10T03:32:34.047Z","avatar_url":"https://github.com/compulim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# memoize-one-with-dispose\n\nA memoization function based on [`memoize-one`](https://npmjs.com/package/memoize-one) with disposing function.\n\n[![npm version](https://badge.fury.io/js/memoize-one-with-dispose.svg)](https://badge.fury.io/js/memoize-one-with-dispose) [![Build Status](https://travis-ci.org/compulim/memoize-one-with-dispose.svg?branch=master)](https://travis-ci.org/compulim/memoize-one-with-dispose) [![Coverage Status](https://coveralls.io/repos/github/compulim/memoize-one-with-dispose/badge.svg)](https://coveralls.io/github/compulim/memoize-one-with-dispose)\n\n## Background\n\n[`memoize-one`](https://npmjs.com/package/memoize-one) is a popular utility package for memoization. It is simple and straightforward. But sometimes, you may use it to hold resources that requires a manual release. This package enhance [`memoize-one`](https://npmjs.com/package/memoize-one) with a disposing function that would call before a new memoized object is created.\n\n\u003e Although JavaScript automatically do garbage collection, sometimes you may be working with resources that requires an explicit stop or cancellation.\n\n## To install\n\nRun `npm install memoize-one memoize-one-with-dispose`.\n\n\u003e This package peer-depends on [`memoize-one`](https://npmjs.com/package/memoize-one).\n\n### Before using `memoize-one-with-dispose`\n\nBefore using this package, you will need to write code like this.\n\n```js\nimport memoize from 'memoize-one';\n\nlet created, lastValue;\n\nconst createOrGetValue = memoize(x =\u003e {\n  created \u0026\u0026 lastValue.dispose();\n  created = true;\n  lastValue = createValue(x);\n\n  return lastValue;\n});\n```\n\n### After using `memoize-one-with-dispose`\n\nAfter using this package, you can write shorter and more readable code like this.\n\n```js\nimport memoizeWithDispose from 'memoize-one-with-dispose';\n\nconst createOrGetValue = memoize(\n  x =\u003e createValue(x),\n  undefined, // pass as equalityFn to memoize-one\n  lastValue =\u003e lastValue.dispose()\n);\n```\n\n# Contributions\n\nLike us? [Star](https://github.com/compulim/memoize-one-with-dispose/stargazers) us.\n\nWant to make it better? [File](https://github.com/compulim/memoize-one-with-dispose/issues) us an issue.\n\nDon't like something you see? [Submit](https://github.com/compulim/memoize-one-with-dispose/pulls) a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompulim%2Fmemoize-one-with-dispose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompulim%2Fmemoize-one-with-dispose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompulim%2Fmemoize-one-with-dispose/lists"}