immer icon indicating copy to clipboard operation
immer copied to clipboard

Typed Arrays support

Open NicolasRannou opened this issue 5 years ago • 2 comments

🚀 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

NicolasRannou avatar Nov 05 '20 16:11 NicolasRannou

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

mweststrate avatar Nov 06 '20 09:11 mweststrate

I have made an attempt to fix this: https://github.com/immerjs/immer/pull/707

Gelio avatar Nov 21 '20 19:11 Gelio

Closing this idea for a lack of demand

mweststrate avatar Jan 02 '23 20:01 mweststrate