unchanged
Version:
A tiny, fast, unopinionated handler for updating JS objects and arrays immutably
16 lines (13 loc) • 6.96 kB
JavaScript
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("curriable"),require("pathington")):"function"==typeof define&&define.amd?define(["exports","curriable","pathington"],r):r((n=n||self).unchanged={},n.curriable,n.pathington)}(this,(function(n,r,t){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function o(){for(var n=0,r=0,t=arguments.length;r<t;r++)n+=arguments[r].length;var o=Array(n),e=0;for(r=0;r<t;r++)for(var u=arguments[r],i=0,c=u.length;i<c;i++,e++)o[e]=u[i];return o}var e=Object,u=e.create,i=e.getOwnPropertySymbols,c=e.getPrototypeOf,f=e.keys,a=e.propertyIsEnumerable,p=Array.isArray,y=Function.prototype.bind.call(Function.prototype.call,Function.prototype.toString),l=Function.prototype.bind.call(Function.prototype.call,e.prototype.toString),v="function"==typeof Symbol&&"function"==typeof Symbol.for,d=v?Symbol.for("react.element"):60103,s=function(n,r,t){for(var o=t,e=0,u=n.length;e<u;e++)o=r(o,n[e]);return o},h=function(n){if(!v)return f(n);var r=i(n);return r.length?f(n).concat(s(r,(function(r,t){return a.call(n,t)&&r.push(t),r}),[])):f(n)},g="function"==typeof e.assign?e.assign:function(n,r){return r?s(h(r),(function(n,t){return n[t]=r[t],n}),Object(n)):n},b=function(n){return u(n.__proto__||c(n))},m=function(n){if(!n||"object"!=typeof n||n.$$typeof===d)return!1;var r=l(n);return"[object Date]"!==r&&"[object RegExp]"!==r},W=function(n){return null==n||p(n)&&!n.length},_=function(n){return"function"==typeof n&&!!~y(n).indexOf("[native code]")},O=function(n,r,t){return"function"==typeof n?n.apply(r,t):void 0},j=function(n){return p(n)?[]:{}},A=function(n){return n.constructor===e?g({},n):p(n)?function(n){for(var r=n.constructor,t=r===Array?[]:new r,o=0,e=n.length;o<e;o++)t[o]=n[o];return t}(n):_(n.constructor)?{}:g(b(n),n)},F=function(n,r){return n===r||n!=n&&r!=r},S=function(n,r){return m(n)?A(n):"number"==typeof r?[]:{}},x=function(n,r){return void 0===n?r:n},w=function(n){return p(n)?n:t.parse(n)},P=function(n,r,t,o){var e=n[o],u=o+1;return u===n.length?t(r,e):r[e]=P(n,S(r[e],n[u]),t,u),r},E=function(n,r,t){var o=w(n),e=S(r,o[0]);return 1===o.length?(t(e,o[0]),e):P(o,e,t,0)},q=function(n,r,t){var o,u=p(n);if(u!==p(r)||!m(n))return m(o=r)?A(o):o;if(u)return n.concat(r);var i=n.constructor===e||_(n.constructor)?{}:b(n);return s(h(r),(function(o,e){return o[e]=t&&m(r[e])?q(n[e],r[e],t):r[e],o}),g(i,n))},$=function(n,r,t){var o=w(n);if(1===o.length)return r?x(r[o[0]],t):t;for(var e=r,u=o[0],i=0;i<o.length-1;i++){if(!e||!e[u])return t;e=e[u],u=o[i+1]}return e?x(e[u],t):t},k=function(n,r,t){var o=W(n),e=o?r:t?t($(n,r)):$(n,r);return p(e)?p(n)?n.concat([e.length]):(o?"":n)+"["+e.length+"]":n},D=function(n,r){if(n.length){for(var t=n.length-1,o=r;o<t;)n[o]=n[o+1],++o;n.length=t}},I=function(){throw new TypeError('handler passed is not of type "function".')},M=Array.isArray,R=Function.prototype.bind.call(Function.prototype.call,Array.prototype.slice);function T(n){return n?function(n,r,t,e,u){void 0===u&&(u=e),"function"!=typeof n&&I();var i=R(arguments,5);if(W(r))return O(n.apply(void 0,o([e],i)),u,t);var c=$(r,e);if(void 0!==c){var f=n.apply(void 0,o([c],i));return O(f,u,t)}}:function(n,r,t,o){void 0===o&&(o=t);var e=W(n)?t:$(n,t);return O(e,o,r)}}function z(n){return n?function(n,r,t){"function"!=typeof n&&I();var e=R(arguments,4);if(W(r))return n.apply(void 0,o([t],e));var u=$(r,t);return void 0===u?u:n.apply(void 0,o([u],e))}:function(n,r){return W(n)?r:$(n,r)}}function B(n){return n?function(n,r,t,e){"function"!=typeof n&&I();var u=R(arguments,4);if(W(t))return n.apply(void 0,o([e],u));var i=$(t,e);return void 0===i?r:n.apply(void 0,o([i],u))}:function(n,r,t){return W(r)?t:$(r,t,n)}}function C(n){return n?function(n,r,t){"function"!=typeof n&&I();var e=R(arguments,3);if(W(r))return!!n.apply(void 0,o([t],e));var u=$(r,t);return void 0!==u&&!!n.apply(void 0,o([u],e))}:function(n,r){return W(n)?null!=r:void 0!==$(n,r)}}function G(n){return n?function(n,r,t,e){"function"!=typeof n&&I();var u=R(arguments,4);return W(r)?F(n.apply(void 0,o([e],u)),t):F(n.apply(void 0,o([$(r,e)],u)),t)}:function(n,r,t){var o=W(n)?t:$(n,t);return F(o,r)}}function H(n,r){return n?function(n,t,e){"function"!=typeof n&&I();var u=R(arguments,3);if(!m(e))return n.apply(void 0,o([e],u));if(W(t)){var i=n.apply(void 0,o([e],u));return i?q(e,i,r):e}var c=!1,f=E(t,e,(function(t,e){var i=n.apply(void 0,o([t[e]],u));i&&(t[e]=q(t[e],i,r),c=!0)}));return c?f:e}:function(n,t,o){return m(o)?W(n)?q(o,t,!0):E(n,o,(function(n,o){n[o]=q(n[o],t,r)})):t}}function J(n){var r=G(n);return function(){return!r.apply(this,arguments)}}function K(n){return n?function(n,r,t){"function"!=typeof n&&I();var e=R(arguments,3);if(W(r)){var u=j(t);return n.apply(void 0,o([u],e))?u:t}var i=$(r,t);return void 0!==i&&n.apply(void 0,o([i],e))?E(r,t,(function(n,r){M(n)?D(n,r):delete n[r]})):t}:function(n,r){return W(n)?j(r):void 0!==$(n,r)?E(n,r,(function(n,r){M(n)?D(n,r):delete n[r]})):r}}function L(n){return n?function(n,r,t){"function"!=typeof n&&I();var e=R(arguments,3);return W(r)?n.apply(void 0,o([t],e)):E(r,t,(function(r,t){r[t]=n.apply(void 0,o([r[t]],e))}))}:function(n,r,t){return W(n)?r:E(n,t,(function(n,t){n[t]=r}))}}function N(n){var r=L(n);return n?function(n,t,o){return r.apply(this,[n,k(t,o,n),o].concat(R(arguments,3)))}:function(n,t,o){return r(k(n,o),t,o)}}var Q=r.curry(N(!1)),U=r.curry(N(!0)),V=r.curry(H(!1,!1)),X=r.curry(H(!0,!1)),Y=r.curry(T(!1),3),Z=r.curry(T(!0),4),nn=r.curry(z(!1)),rn=r.curry(B(!1)),tn=r.curry(z(!0)),on=r.curry(B(!0)),en=r.curry(C(!1)),un=r.curry(C(!0)),cn=r.curry(G(!1)),fn=r.curry(G(!0)),an=r.curry(H(!1,!0)),pn=r.curry(H(!0,!0)),yn=r.curry(J(!1)),ln=r.curry(J(!0)),vn=r.curry(K(!1)),dn=r.curry(K(!0)),sn=r.curry(L(!1)),hn=r.curry(L(!0));Object.defineProperty(n,"__",{enumerable:!0,get:function(){return r.__}}),n.add=Q,n.addWith=U,n.assign=V,n.assignWith=X,n.call=Y,n.callWith=Z,n.get=nn,n.getOr=rn,n.getWith=tn,n.getWithOr=on,n.has=en,n.hasWith=un,n.is=cn,n.isWith=fn,n.merge=an,n.mergeWith=pn,n.not=yn,n.notWith=ln,n.remove=vn,n.removeWith=dn,n.set=sn,n.setWith=hn,Object.defineProperty(n,"__esModule",{value:!0})}));