Skip to content

Commit

Permalink
feat(operator): caching for methods and getter
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Aug 22, 2018
1 parent 805ee9e commit a70e937
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/operator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint func-names: 0 */
/* eslint no-param-reassign: 0 */
/* eslint getter-return: 0 */

const X = 'x';
const Y = 'y';
Expand Down Expand Up @@ -97,8 +98,19 @@ export function cachedValueOf(Vector) {
export function cachedMethod(Vector, name) {
const org = Vector.prototype[name];
Vector.prototype[name] = function (...args) {
return v3resultCache[inProgress].call(this, org, args, name);
return v3resultCache[inProgress].call(this, org, args);
};
}

export function cachedGetter(/* Vector, name */) {}
export function cachedGetter(Vector, name) {
const desc = Object.getOwnPropertyDescriptor(Vector.prototype, name);
const org = function () {
return desc.get.call(this);
};

Object.defineProperty(Vector.prototype, name, {
get() {
return v3resultCache[inProgress].call(this, org);
}
});
}

0 comments on commit a70e937

Please sign in to comment.