{"id":13748617,"url":"https://github.com/shawncplus/memoization-behavior","last_synced_at":"2026-01-19T15:33:55.083Z","repository":{"id":136670396,"uuid":"77083413","full_name":"shawncplus/memoization-behavior","owner":"shawncplus","description":"Polymer behavior adding memoization helpers","archived":false,"fork":false,"pushed_at":"2016-12-27T18:10:19.000Z","size":11,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-04T07:02:08.173Z","etag":null,"topics":["caching","memoize","polymer"],"latest_commit_sha":null,"homepage":null,"language":"HTML","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/shawncplus.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-21T20:21:09.000Z","updated_at":"2016-12-25T19:42:08.000Z","dependencies_parsed_at":"2024-01-15T00:54:06.692Z","dependency_job_id":"dcbae247-da79-4bf9-84ca-5c39ed139135","html_url":"https://github.com/shawncplus/memoization-behavior","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawncplus%2Fmemoization-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawncplus%2Fmemoization-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawncplus%2Fmemoization-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shawncplus%2Fmemoization-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shawncplus","download_url":"https://codeload.github.com/shawncplus/memoization-behavior/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224859697,"owners_count":17381676,"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":["caching","memoize","polymer"],"created_at":"2024-08-03T07:00:45.764Z","updated_at":"2026-01-19T15:33:55.071Z","avatar_url":"https://github.com/shawncplus.png","language":"HTML","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"memoization-behavior [![Build Status](https://travis-ci.org/shawncplus/memoization-behavior.svg?branch=master)](https://travis-ci.org/shawncplus/memoization-behavior) [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://beta.webcomponents.org/element/shawncplus/memoization-behavior)\n\n====================\n\n`Biddle.MemoizationBehavior` allows you to define a computed property\nas memoizable (http://en.wikipedia.org/wiki/Memoization) with `_memoizeComputed`\nor more generally memoize any given function with `_memoize`\n\n\u003e Note: Methods of this behavior are \"private\" as a matter of convention and will\n\u003e not appear on beta.webcomponents.org hosted documentation. I've made the\n\u003e executive decision that it wouldn't be wise to allow the memoization methods\n\u003e to be published as part of an element's public API. Doing so may entice some\n\u003e hapless individual into creating some kind of element whose purpose is to\n\u003e memoize all computed properties in all elements ever.\n\nTo implement a computed property as memoizable in the simplest fashion (although\nthis is a trivial example, you would likely only want to memoize expensive functions)\n\n    behaviors: [\n        Biddle.MemoizationBehavior,\n    ],\n\n    properties: {\n        firstName: String,\n        lastName: String,\n        fullName: {\n            type: String,\n            computed: '_memoizeComputed(\"fullName\", firstName, lastName)'\n            method: '_getFullName'\n        }\n    },\n\n    _getFullName: function (first, last) {\n        return first + ' ' + last;\n    }\n\nGiven that the default hash function is `JSON.stringify` which may be inappropriate\nfor object/array parameters you may wish to override the default hashing method\nfor a specific property.\n\n    properties: {\n        foo: Object,\n        bar: Object,\n        foobar: {\n            type: String,\n            computed: '_memoizeComputed(\"fullName\", foo, bar)'\n            method: '_computeFoobar',\n            hashFn: (foo, bar) =\u003e foo.id + ':' + bar.id\n        }\n    },\n\nTo generally memoize any function you may do the following\n\n    var someValue = this._memoize(this.someExpensiveFunction)(arg2, arg2, arg3);\n\nCache invalidation happens manually with the `_invalidateMemoizeCache` method\n\n    var foo = this._memoize(this.bar)('Hello');\n    // ...\n    this._invalidateMemoizeCache(this.bar);\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshawncplus%2Fmemoization-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshawncplus%2Fmemoization-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshawncplus%2Fmemoization-behavior/lists"}