Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
letsfreezethat
Advanced tools
LetsFreezeThat is an unapologetically small and minimalisitc library to make working with immutable objects in JavaScript less of a chore.
npm install letsfreezethat
{ lets, freeze, thaw, } = require 'letsfreezethat'
d = lets { foo: 'bar', nested: [ 2, 3, 5, 7, ], } # create object
e = lets d, ( d ) -> d.nested.push 11 # modify copy in callback
console.log 'd ', d # { foo: 'bar', nested: [ 2, 3, 5, 7 ] }
console.log 'e ', e # { foo: 'bar', nested: [ 2, 3, 5, 7, 11 ] }
console.log 'd is e ', d is e # false
console.log 'Object.isFrozen d ', Object.isFrozen d # true
console.log 'Object.isFrozen d.nested ', Object.isFrozen d.nested # true
console.log 'Object.isFrozen e ', Object.isFrozen e # true
console.log 'Object.isFrozen e.nested ', Object.isFrozen e.nested # true
LetsFreezeThat copies the core functionality of immer (also see here); the basic insight being that
Now immer
does a lot more than that as it also allows you to track changes and so on. It also allows
you to improve performance by foregoing object.freeze()
altogether (something that I may implement
in LetsFreezeThat at a later point in time).
What I wanted was a library so small that performance was probably optimal; turns out 50 LOC is generous
for a functional subset of immeer
.
you can use the lets()
, freeze()
and thaw()
methods by require
ing them as in { lets, freeze, thaw, } = require 'letsfreezethat'
, but probably you only want lets()
. lets()
is similar to immer
's
produce()
, except simpler.
lets()
takes a value to start with, call it d
, and an optional callback function to modify d
.
Where the callback is not given, lets d
is equivalent to freeze d
which returns a copy of d
with all
properties recursively frozen.
Where the callback is given, that's where you can modify a temporary copy of the first argument d
. I've
come to always name those copies the same—actually d
most of the time, but that can be confusing. In
short, you should think of
d = lets d, ( d ) -> d.foo = 'baz'
as if it was written more like this:
frozen_data_v2 = lets frozen_data_v1, ( mutable_copy ) -> mutable_copy.foo = 'baz'
LetsFreezeThat is around 2.7 times as fast as immer
, according to my highly scientific tests.
FAQs
An utterly minimal immutability library in the spirit of immer
The npm package letsfreezethat receives a total of 18 weekly downloads. As such, letsfreezethat popularity was classified as not popular.
We found that letsfreezethat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.