Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
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 0 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.