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

Shared Value array proxy doesn't support .slice #195

Open
wuguishifu opened this issue May 12, 2024 · 1 comment
Open

Shared Value array proxy doesn't support .slice #195

wuguishifu opened this issue May 12, 2024 · 1 comment

Comments

@wuguishifu
Copy link

wuguishifu commented May 12, 2024

I'm trying to take the last N elements of a Shared Value array, but calling .slice throws an error.

Reproducable code:

const array = useSharedValue<number[]>([1, 2, 3]);
array.value.slice(1); // throws "Error: array.value.slice is not a function (it is undefined)"

I believe this is because the .slice function was not implemented in #36. Is there any way for me to either extend this functionality into the proxy in my code base or to use something else?

For additional context, I'm trying to add data to this array from inside a Vision Camera Skia frame processor, and then also in the frame processor I'm rendering the last 1000 data points in a graph. To get around using .slice, I've been calling Object.values(array.value) and then running .slice on the output array. However, for large arrays (1000+ items), this because very inefficient (20+ ms). I'm also open to suggestions for alternate strategies for doing this if it would be too difficult to extend the functionality.

Thanks!

@mrousavy
Copy link
Member

Yea we could just add slice(..) to our array proxy.

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

No branches or pull requests

2 participants