3 ms·
A use case I had for proxies was a circular array type: https://github.com/philbooth/hoopy https://github.com/philbooth/hoopy If the index overflows in either
by philbo 8y ago
A use case I had for proxies was a circular array type:
https://github.com/philbooth/hoopy https://github.com/philbooth/hoopy
If the index overflows in either direction, loop back round to the start/end of the array. I wanted a circular array to use as a fixed-length buffer for receiving data in a streaming JSON parser I wrote:
https://github.com/philbooth/bfj/blob/61087c194d5675c75569a2e08617a98609b16ead/src/match.js#L197-L201 https://github.com/philbooth/bfj/blob/61087c194d5675c75569a2...
- lioeters 8y agoA circular array type, love it! It looks like an excellent use case of proxies.
- flashgordon 8y agoTechnically the type should still be an Array with the backing implementation having a circular array behavior no?
- lioeters 8y agoIndeed, it extends native Array: https://github.com/philbooth/hoopy/blob/master/index.js#L3 https://github.com/philbooth/hoopy/blob/master/index.js#L3
- antoaravinth 8y agoCool. I was seeing source of inner js, which in deed uses proxies to create structural sharing. https://github.com/mweststrate/immer https://github.com/mweststrate/immer