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

Provide prev parameter to reactiveComputed callback #4331

Open
4 tasks done
RomanSkrypnik opened this issue Nov 8, 2024 · 0 comments
Open
4 tasks done

Provide prev parameter to reactiveComputed callback #4331

RomanSkrypnik opened this issue Nov 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@RomanSkrypnik
Copy link

RomanSkrypnik commented Nov 8, 2024

Clear and concise description of the problem

Currently, every time reactiveComputed dependencies get updated - reactiveComputed resets to initial state
Example:

const test = ref(0);

const obj = reactiveComputed(() => ({ test: test.value, num: 2 })); // { test: 0, num: 2 }

obj.num = 5;
console.log(obj) { test: 0, num: 5 }

test.value = 1;
console.log(obj); // { test: 1, num: 2 } - **num** has been reset

Suggested solution

It would be a great solution to add prev param to reactiveComputed callback:

const test = ref(0);

const obj = reactiveComputed(
  (prev) => ({ test: test.value, num: prev.num ?? 2 })  // { test: 0, num: 2 }
);

obj.num = 5;
console.log(obj); { test: 0, num: 5 }

test.value = 1;
console.log(obj); // { test: 1, num: 5 }

Alternative

No response

Additional context

No response

Validations

@RomanSkrypnik RomanSkrypnik added the enhancement New feature or request label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant