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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed Arrays support #696

Closed
NicolasRannou opened this issue Nov 5, 2020 · 3 comments
Closed

Typed Arrays support #696

NicolasRannou opened this issue Nov 5, 2020 · 3 comments

Comments

@NicolasRannou
Copy link

馃殌 Feature Proposal

Support typed arrays in Immer.

Motivation

Sometimes typed arrays is just the best way to store data. One of the aspects is that if you use web workers, it is much more efficient to pass TypedArrays (Array Buffer) instead of copying things around. Also, from my understanding, those are just the most efficient data structure.

I guess I'm mostly curious whether that's actually possible and how much effort that would take.

Can this be solved in user-land code?

Nope.

Example

import produce from "immer"

const baseState = [
    {
        data: new Uint16(9000),
        data3D:[new Uint16(6756), new Uint16(789)]
    }
]

const nextState = produce(baseState, draftState => {
    draftState[0].data[93] = 0;
})

// or apply a patch
@mweststrate
Copy link
Collaborator

Feel free to create a plugin that supports these data types, similar to how Map / Set is supported. Or it might be sufficient to widen the array detection in Immer to support those collections without any further changes

@Gelio
Copy link
Contributor

Gelio commented Nov 21, 2020

I have made an attempt to fix this: #707

@mweststrate
Copy link
Collaborator

Closing this idea for a lack of demand

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

Successfully merging a pull request may close this issue.

3 participants