Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoized methods of the same instance are mixed #77

Closed
bencehornak opened this issue Jul 15, 2021 · 0 comments · Fixed by #78
Closed

Memoized methods of the same instance are mixed #77

bencehornak opened this issue Jul 15, 2021 · 0 comments · Fixed by #78

Comments

@bencehornak
Copy link
Contributor

If two functions are decorated of the same instance, their memoized values get mixed with the latest version (v9.0.0).

Take for example:

class TestClass {
	@memDecorator()
	fn1() {
		return 1;
	}

	@memDecorator()
	counter2() {
		return 2;
	}
}

const instance = new TestClass();
console.log(instance.fn1()); // prints 1
console.log(instance.fn2()); // also prints 1 !!!

I would expect the second call to return 2, but it returns 1.

The memoized function in my understanding should be connected 1:1 to the combination of instance and propterty, whereas it is currently connected 1:1 to instances (#74).

I guess a little bit more complicated internal data structure is needed instead of the current implementation of decoratorInstanceMap, will open a PR that adds a test and demonstrates a possible solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant