Skip to content

Commit a70e937

Browse files
committed
feat(operator): caching for methods and getter
1 parent 805ee9e commit a70e937

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/operator.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint func-names: 0 */
22
/* eslint no-param-reassign: 0 */
3+
/* eslint getter-return: 0 */
34

45
const X = 'x';
56
const Y = 'y';
@@ -97,8 +98,19 @@ export function cachedValueOf(Vector) {
9798
export function cachedMethod(Vector, name) {
9899
const org = Vector.prototype[name];
99100
Vector.prototype[name] = function (...args) {
100-
return v3resultCache[inProgress].call(this, org, args, name);
101+
return v3resultCache[inProgress].call(this, org, args);
101102
};
102103
}
103104

104-
export function cachedGetter(/* Vector, name */) {}
105+
export function cachedGetter(Vector, name) {
106+
const desc = Object.getOwnPropertyDescriptor(Vector.prototype, name);
107+
const org = function () {
108+
return desc.get.call(this);
109+
};
110+
111+
Object.defineProperty(Vector.prototype, name, {
112+
get() {
113+
return v3resultCache[inProgress].call(this, org);
114+
}
115+
});
116+
}

0 commit comments

Comments
 (0)