Last active
June 12, 2022 22:21
-
-
Save 421p/2a32a5aa7cd1ed4bb55413ca34c1b0c3 to your computer and use it in GitHub Desktop.
Revisions
-
421p revised this gist
Feb 26, 2017 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ export class Foo{ @memoize get bar() { return 1 + 1; // will be calculated once and then cached } } -
421p revised this gist
Feb 26, 2017 . No changes.There are no files selected for viewing
-
421p created this gist
Feb 26, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ export function memoize(target: any, prop: string, descriptor: PropertyDescriptor) { let original = descriptor.get; descriptor.get = function (...args: any[]) { const privateProp = `__memoized_${prop}`; if (!this.hasOwnProperty(privateProp)) { Object.defineProperty(this, privateProp, { configurable: false, enumerable: false, writable: false, value: original.apply(this, args) }); } return this[privateProp]; }; }