Socket
Socket
Sign inDemoInstall

immer

Package Overview
Dependencies
Maintainers
1
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immer - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

4

changelog.md
# Changelog
### 0.8.1
* Fixed [#66](https://github.com/mweststrate/immer/pull/66), assigning an already frozen object to a state threw resulting in exceptions being thrown as Immer unnecessarily tried to rewrite them.
### 0.8.0

@@ -4,0 +8,0 @@

55

dist/immer.js

@@ -45,2 +45,28 @@ 'use strict';

function finalizeNonProxiedObject(parent, finalizer) {
// If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original
// tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well
if (!isProxyable(parent)) return;
if (Object.isFrozen(parent)) return;
var modified = false;
if (Array.isArray(parent)) {
for (var i = 0; i < parent.length; i++) {
var child = parent[i];
if (isProxy(child)) {
parent[i] = finalizer(child);
modified = true;
} else finalizeNonProxiedObject(child, finalizer);
}
} else {
for (var key in parent) {
var _child = parent[key];
if (isProxy(_child)) {
parent[key] = finalizer(_child);
modified = true;
} else finalizeNonProxiedObject(_child, finalizer);
}
}
if (modified) freeze(parent);
}
// @ts-check

@@ -169,16 +195,3 @@

} else if (base !== null && (typeof base === "undefined" ? "undefined" : _typeof(base)) === "object") {
// If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original
// tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well
// TODO: optimize this; walk the tree without writing to find proxies
if (Array.isArray(base)) {
for (var i = 0; i < base.length; i++) {
base[i] = finalize(base[i]);
}return freeze(base);
}
var proto = Object.getPrototypeOf(base);
if (proto === null || proto === Object.prototype) {
for (var key in base) {
base[key] = finalize(base[key]);
}return freeze(base);
}
finalizeNonProxiedObject(base, finalize);
}

@@ -361,15 +374,3 @@ return base;

} else if (proxy !== null && (typeof proxy === "undefined" ? "undefined" : _typeof(proxy)) === "object") {
// If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original
// tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well
if (Array.isArray(proxy)) {
for (var i = 0; i < proxy.length; i++) {
proxy[i] = finalize$1(proxy[i]);
}return freeze(proxy);
}
var proto = Object.getPrototypeOf(proxy);
if (proto === null || proto === Object.prototype) {
for (var key in proxy) {
proxy[key] = finalize$1(proxy[key]);
}return freeze(proxy);
}
finalizeNonProxiedObject(proxy, finalize$1);
}

@@ -376,0 +377,0 @@ return proxy;

@@ -41,2 +41,28 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {

function finalizeNonProxiedObject(parent, finalizer) {
// If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original
// tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well
if (!isProxyable(parent)) return;
if (Object.isFrozen(parent)) return;
var modified = false;
if (Array.isArray(parent)) {
for (var i = 0; i < parent.length; i++) {
var child = parent[i];
if (isProxy(child)) {
parent[i] = finalizer(child);
modified = true;
} else finalizeNonProxiedObject(child, finalizer);
}
} else {
for (var key in parent) {
var _child = parent[key];
if (isProxy(_child)) {
parent[key] = finalizer(_child);
modified = true;
} else finalizeNonProxiedObject(_child, finalizer);
}
}
if (modified) freeze(parent);
}
// @ts-check

@@ -165,16 +191,3 @@

} else if (base !== null && (typeof base === "undefined" ? "undefined" : _typeof(base)) === "object") {
// If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original
// tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well
// TODO: optimize this; walk the tree without writing to find proxies
if (Array.isArray(base)) {
for (var i = 0; i < base.length; i++) {
base[i] = finalize(base[i]);
}return freeze(base);
}
var proto = Object.getPrototypeOf(base);
if (proto === null || proto === Object.prototype) {
for (var key in base) {
base[key] = finalize(base[key]);
}return freeze(base);
}
finalizeNonProxiedObject(base, finalize);
}

@@ -357,15 +370,3 @@ return base;

} else if (proxy !== null && (typeof proxy === "undefined" ? "undefined" : _typeof(proxy)) === "object") {
// If finalize is called on an object that was not a proxy, it means that it is an object that was not there in the original
// tree and it could contain proxies at arbitrarily places. Let's find and finalize them as well
if (Array.isArray(proxy)) {
for (var i = 0; i < proxy.length; i++) {
proxy[i] = finalize$1(proxy[i]);
}return freeze(proxy);
}
var proto = Object.getPrototypeOf(proxy);
if (proto === null || proto === Object.prototype) {
for (var key in proxy) {
proxy[key] = finalize$1(proxy[key]);
}return freeze(proxy);
}
finalizeNonProxiedObject(proxy, finalize$1);
}

@@ -372,0 +373,0 @@ return proxy;

@@ -1,2 +0,2 @@

var e,r;e=this,r=function(e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=Symbol("immer-proxy-state"),t=!0;function o(e){return!!e&&!!e[n]}function i(e){if(!e)return!1;if("object"!==(void 0===e?"undefined":r(e)))return!1;if(Array.isArray(e))return!0;var n=Object.getPrototypeOf(e);return null===n||n===Object.prototype}function f(e){return t&&Object.freeze(e),e}var a=null,u={get:function(e,r){if(r===n)return e;if(e.modified){var t=e.copy[r];return!o(t)&&i(t)?e.copy[r]=l(e,t):t}if(r in e.proxies)return e.proxies[r];var f=e.base[r];return!o(f)&&i(f)?e.proxies[r]=l(e,f):f},has:function(e,r){return r in d(e)},ownKeys:function(e){return Reflect.ownKeys(d(e))},set:function(e,r,n){if(!e.modified){if(r in e.base&&Object.is(e.base[r],n)||r in e.proxies&&e.proxies[r]===n)return!0;p(e)}return e.copy[r]=n,!0},deleteProperty:function(e,r){return p(e),delete e.copy[r],!0},getOwnPropertyDescriptor:function(e,r){var n=e.modified?e.copy:r in e.proxies?e.proxies:e.base,t=Reflect.getOwnPropertyDescriptor(n,r);!t||Array.isArray(n)&&"length"===r||(t.configurable=!0);return t},defineProperty:function(){throw new Error("Immer does currently not support defining properties on draft objects")},setPrototypeOf:function(){throw new Error("Don't even try this...")}},c={},s=function(e){c[e]=function(){return arguments[0]=arguments[0][0],u[e].apply(this,arguments)}};for(var y in u)s(y);function d(e){return!0===e.modified?e.copy:e.base}function p(e){e.modified||(e.modified=!0,e.copy=Array.isArray(e.base)?e.base.slice():Object.assign({},e.base),Object.assign(e.copy,e.proxies),e.parent&&p(e.parent))}function l(e,r){var n={modified:!1,finalized:!1,parent:e,base:r,copy:void 0,proxies:{}},t=void 0;return t=Array.isArray(r)?Proxy.revocable([n],c):Proxy.revocable(n,u),a.push(t),t.proxy}function b(e){if(o(e)){var t=e[n];return!0===t.modified?!0===t.finalized?t.copy:(t.finalized=!0,Array.isArray(t.base)?function(e){for(var r=e.copy,n=e.base,t=0;t<r.length;t++)r[t]!==n[t]&&(r[t]=b(r[t]));return f(r)}(t):function(e){var r=e.copy,n=e.base;for(var t in r)r[t]!==n[t]&&(r[t]=b(r[t]));return f(r)}(t)):t.base}if(null!==e&&"object"===(void 0===e?"undefined":r(e))){if(Array.isArray(e)){for(var i=0;i<e.length;i++)e[i]=b(e[i]);return f(e)}var a=Object.getPrototypeOf(e);if(null===a||a===Object.prototype){for(var u in e)e[u]=b(e[u]);return f(e)}}return e}var v={},h=null;function m(e){return e.hasCopy?e.copy:e.base}function g(e){e.modified||(e.modified=!0,e.parent&&g(e.parent))}function j(e){e.hasCopy||(e.hasCopy=!0,e.copy=Array.isArray(e.base)?e.base.slice():Object.assign({},e.base))}function O(e,r){var t,o,i=void 0;Array.isArray(r)?i=function(e){for(var r=new Array(e.length),n=0;n<e.length;n++)Object.defineProperty(r,""+n,w(""+n));return r}(r):(t=r,o=Object.assign({},t),Object.keys(t).forEach(function(e){return Object.defineProperty(o,e,w(e))}),i=o);var f,a,u,c={modified:!1,hasCopy:!1,parent:e,base:r,proxy:i,copy:void 0,finished:!1,finalizing:!1};return f=i,a=n,u=c,Object.defineProperty(f,a,{value:u,enumerable:!1,writable:!0}),h.push(c),i}function w(e){return v[e]||(v[e]={configurable:!0,enumerable:!0,get:function(){return function(e,r){x(e);var n=m(e)[r];return e.finalizing||o(n)||!i(n)?n:(j(e),e.copy[r]=O(e,n))}(this[n],e)},set:function(r){!function(e,r,n){if(x(e),!e.modified){if(Object.is(m(e)[r],n))return;g(e)}j(e),e.copy[r]=n}(this[n],e,r)}})}function x(e){if(!0===e.finished)throw new Error("Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process?")}function A(e){if(o(e)){var t=e[n];return!0===t.modified?Array.isArray(t.base)?function(e,r){for(var n=e.slice(),t=r.base,o=0;o<n.length;o++)n[o]!==t[o]&&(n[o]=A(n[o]));return f(n)}(e,t):function(e,r){var n=Object.assign({},e),t=r.base;for(var o in n)e[o]!==t[o]&&(n[o]=A(n[o]));return f(n)}(e,t):t.base}if(null!==e&&"object"===(void 0===e?"undefined":r(e))){if(Array.isArray(e)){for(var i=0;i<e.length;i++)e[i]=A(e[i]);return f(e)}var a=Object.getPrototypeOf(e);if(null===a||a===Object.prototype){for(var u in e)e[u]=A(e[u]);return f(e)}}return e}function P(e,n){var t=h;h=[];try{var o=O(void 0,e),i=n(o);!Object.is(i,void 0)&&console.warn("Immer callback expects no return value. However "+(void 0===i?"undefined":r(i))+" was returned");for(var f=0;f<h.length;f++)h[f].finalizing=!0;!function(){for(var e=h.length-1;e>=0;e--){var n=h[e];!1===n.modified&&(Array.isArray(n.base)?(f=n).proxy.length!==f.base.length&&g(n):(t=n,o=Object.keys(t.base),i=Object.keys(t.proxy),function(e,n){if(Object.is(e,n))return!0;if("object"!==(void 0===e?"undefined":r(e))||null===e||"object"!==(void 0===n?"undefined":r(n))||null===n)return!1;var t=Object.keys(e),o=Object.keys(n);if(t.length!==o.length)return!1;for(var i=0;i<t.length;i++)if(!hasOwnProperty.call(n,t[i])||!Object.is(e[t[i]],n[t[i]]))return!1;return!0}(o,i)||g(n)))}var t,o,i,f}();for(var a=A(o),u=0;u<h.length;u++)h[u].finished=!0;return a}finally{h=t}}var k="undefined"!=typeof Proxy;e.default=function e(n,t){if(1===arguments.length){if("function"!=typeof n)throw new Error("if produce is called with 1 argument, the first argument should be a function");return function(){var r=arguments;return e(r[0],function(e){r[0]=e,n.apply(null,r)})}}if(2!==arguments.length)throw new Error("produce expects 1 or 2 arguments, got "+arguments.length);if(!i(n))throw new Error("the first argument to produce should be a plain object or array, got "+(void 0===n?"undefined":r(n)));if("function"!=typeof t)throw new Error("the second argument to produce should be a function");return k?function(e,n){var t=a;a=[];try{var o=l(void 0,e),i=n(o);!Object.is(i,void 0)&&console.warn("Immer callback expects no return value. However "+(void 0===i?"undefined":r(i))+" was returned");var f=b(o);return a.forEach(function(e){return e.revoke()}),f}finally{a=t}}(n,t):P(n,t)},e.setUseProxies=function(e){k=e},e.setAutoFreeze=function(e){t=e},Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.immer={});
var e,r;e=this,r=function(e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=Symbol("immer-proxy-state"),t=!0;function o(e){return!!e&&!!e[n]}function i(e){if(!e)return!1;if("object"!==(void 0===e?"undefined":r(e)))return!1;if(Array.isArray(e))return!0;var n=Object.getPrototypeOf(e);return null===n||n===Object.prototype}function a(e){return t&&Object.freeze(e),e}function f(e,r){if(i(e)&&!Object.isFrozen(e)){var n=!1;if(Array.isArray(e))for(var t=0;t<e.length;t++){var u=e[t];o(u)?(e[t]=r(u),n=!0):f(u,r)}else for(var c in e){var s=e[c];o(s)?(e[c]=r(s),n=!0):f(s,r)}n&&a(e)}}var u=null,c={get:function(e,r){if(r===n)return e;if(e.modified){var t=e.copy[r];return!o(t)&&i(t)?e.copy[r]=b(e,t):t}if(r in e.proxies)return e.proxies[r];var a=e.base[r];return!o(a)&&i(a)?e.proxies[r]=b(e,a):a},has:function(e,r){return r in p(e)},ownKeys:function(e){return Reflect.ownKeys(p(e))},set:function(e,r,n){if(!e.modified){if(r in e.base&&Object.is(e.base[r],n)||r in e.proxies&&e.proxies[r]===n)return!0;l(e)}return e.copy[r]=n,!0},deleteProperty:function(e,r){return l(e),delete e.copy[r],!0},getOwnPropertyDescriptor:function(e,r){var n=e.modified?e.copy:r in e.proxies?e.proxies:e.base,t=Reflect.getOwnPropertyDescriptor(n,r);!t||Array.isArray(n)&&"length"===r||(t.configurable=!0);return t},defineProperty:function(){throw new Error("Immer does currently not support defining properties on draft objects")},setPrototypeOf:function(){throw new Error("Don't even try this...")}},s={},d=function(e){s[e]=function(){return arguments[0]=arguments[0][0],c[e].apply(this,arguments)}};for(var y in c)d(y);function p(e){return!0===e.modified?e.copy:e.base}function l(e){e.modified||(e.modified=!0,e.copy=Array.isArray(e.base)?e.base.slice():Object.assign({},e.base),Object.assign(e.copy,e.proxies),e.parent&&l(e.parent))}function b(e,r){var n={modified:!1,finalized:!1,parent:e,base:r,copy:void 0,proxies:{}},t=void 0;return t=Array.isArray(r)?Proxy.revocable([n],s):Proxy.revocable(n,c),u.push(t),t.proxy}function v(e){if(o(e)){var t=e[n];return!0===t.modified?!0===t.finalized?t.copy:(t.finalized=!0,Array.isArray(t.base)?function(e){for(var r=e.copy,n=e.base,t=0;t<r.length;t++)r[t]!==n[t]&&(r[t]=v(r[t]));return a(r)}(t):function(e){var r=e.copy,n=e.base;for(var t in r)r[t]!==n[t]&&(r[t]=v(r[t]));return a(r)}(t)):t.base}return null!==e&&"object"===(void 0===e?"undefined":r(e))&&f(e,v),e}var h={},m=null;function g(e){return e.hasCopy?e.copy:e.base}function j(e){e.modified||(e.modified=!0,e.parent&&j(e.parent))}function O(e){e.hasCopy||(e.hasCopy=!0,e.copy=Array.isArray(e.base)?e.base.slice():Object.assign({},e.base))}function w(e,r){var t,o,i=void 0;Array.isArray(r)?i=function(e){for(var r=new Array(e.length),n=0;n<e.length;n++)Object.defineProperty(r,""+n,x(""+n));return r}(r):(t=r,o=Object.assign({},t),Object.keys(t).forEach(function(e){return Object.defineProperty(o,e,x(e))}),i=o);var a,f,u,c={modified:!1,hasCopy:!1,parent:e,base:r,proxy:i,copy:void 0,finished:!1,finalizing:!1};return a=i,f=n,u=c,Object.defineProperty(a,f,{value:u,enumerable:!1,writable:!0}),m.push(c),i}function x(e){return h[e]||(h[e]={configurable:!0,enumerable:!0,get:function(){return function(e,r){A(e);var n=g(e)[r];return e.finalizing||o(n)||!i(n)?n:(O(e),e.copy[r]=w(e,n))}(this[n],e)},set:function(r){!function(e,r,n){if(A(e),!e.modified){if(Object.is(g(e)[r],n))return;j(e)}O(e),e.copy[r]=n}(this[n],e,r)}})}function A(e){if(!0===e.finished)throw new Error("Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process?")}function P(e){if(o(e)){var t=e[n];return!0===t.modified?Array.isArray(t.base)?function(e,r){for(var n=e.slice(),t=r.base,o=0;o<n.length;o++)n[o]!==t[o]&&(n[o]=P(n[o]));return a(n)}(e,t):function(e,r){var n=Object.assign({},e),t=r.base;for(var o in n)e[o]!==t[o]&&(n[o]=P(n[o]));return a(n)}(e,t):t.base}return null!==e&&"object"===(void 0===e?"undefined":r(e))&&f(e,P),e}function k(e,n){var t=m;m=[];try{var o=w(void 0,e),i=n(o);!Object.is(i,void 0)&&console.warn("Immer callback expects no return value. However "+(void 0===i?"undefined":r(i))+" was returned");for(var a=0;a<m.length;a++)m[a].finalizing=!0;!function(){for(var e=m.length-1;e>=0;e--){var n=m[e];!1===n.modified&&(Array.isArray(n.base)?(a=n).proxy.length!==a.base.length&&j(n):(t=n,o=Object.keys(t.base),i=Object.keys(t.proxy),function(e,n){if(Object.is(e,n))return!0;if("object"!==(void 0===e?"undefined":r(e))||null===e||"object"!==(void 0===n?"undefined":r(n))||null===n)return!1;var t=Object.keys(e),o=Object.keys(n);if(t.length!==o.length)return!1;for(var i=0;i<t.length;i++)if(!hasOwnProperty.call(n,t[i])||!Object.is(e[t[i]],n[t[i]]))return!1;return!0}(o,i)||j(n)))}var t,o,i,a}();for(var f=P(o),u=0;u<m.length;u++)m[u].finished=!0;return f}finally{m=t}}var z="undefined"!=typeof Proxy;e.default=function e(n,t){if(1===arguments.length){if("function"!=typeof n)throw new Error("if produce is called with 1 argument, the first argument should be a function");return function(){var r=arguments;return e(r[0],function(e){r[0]=e,n.apply(null,r)})}}if(2!==arguments.length)throw new Error("produce expects 1 or 2 arguments, got "+arguments.length);if(!i(n))throw new Error("the first argument to produce should be a plain object or array, got "+(void 0===n?"undefined":r(n)));if("function"!=typeof t)throw new Error("the second argument to produce should be a function");return z?function(e,n){var t=u;u=[];try{var o=b(void 0,e),i=n(o);!Object.is(i,void 0)&&console.warn("Immer callback expects no return value. However "+(void 0===i?"undefined":r(i))+" was returned");var a=v(o);return u.forEach(function(e){return e.revoke()}),a}finally{u=t}}(n,t):k(n,t)},e.setUseProxies=function(e){z=e},e.setAutoFreeze=function(e){t=e},Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.immer={});
//# sourceMappingURL=immer.umd.js.map
{
"name": "immer",
"version": "0.8.0",
"version": "0.8.1",
"description": "Create your next immutable state by mutating the current one",

@@ -5,0 +5,0 @@ "main": "dist/immer.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc