@rpldy/simple-state
Advanced tools
Comparing version 1.3.1 to 1.4.0-rc.0
@@ -14,9 +14,5 @@ "use strict"; | ||
exports.unwrap = void 0; | ||
var _shared = require("@rpldy/shared"); | ||
var _consts = require("./consts"); | ||
var _utils = require("./utils"); | ||
const mergeWithSymbols = (0, _shared.getMerge)({ | ||
@@ -26,5 +22,3 @@ withSymbols: true, | ||
}); | ||
const getIsUpdateable = proxy => (0, _shared.isProduction)() ? true : proxy[_consts.STATE_SYM].isUpdateable; | ||
const setIsUpdateable = (proxy, value) => { | ||
@@ -35,6 +29,4 @@ if (!(0, _shared.isProduction)()) { | ||
}; | ||
const deepProxy = (obj, traps) => { | ||
let proxy; | ||
if ((0, _utils.isProxiable)(obj)) { | ||
@@ -45,3 +37,2 @@ if (!(0, _utils.isProxy)(obj)) { | ||
} | ||
Object.keys(obj).forEach(key => { | ||
@@ -51,7 +42,6 @@ obj[key] = deepProxy(obj[key], traps); | ||
} | ||
return proxy || obj; | ||
}; | ||
const unwrapProxy = proxy => (0, _utils.isProxy)(proxy) ? (0, _shared.clone)(proxy, mergeWithSymbols) : proxy; | ||
const unwrapProxy = proxy => (0, _utils.isProxy)(proxy) ? (0, _shared.clone)(proxy, mergeWithSymbols) : proxy; | ||
/** | ||
@@ -72,6 +62,3 @@ * deep proxies an object so it is only updateable through an update callback. | ||
*/ | ||
exports.unwrap = unwrapProxy; | ||
const createState = obj => { | ||
@@ -83,3 +70,2 @@ const traps = { | ||
} | ||
return true; | ||
@@ -100,7 +86,5 @@ }, | ||
} | ||
return true; | ||
} | ||
}; | ||
if (!(0, _shared.isProduction)() && !(0, _utils.isProxy)(obj)) { | ||
@@ -114,3 +98,2 @@ Object.defineProperty(obj, _consts.STATE_SYM, { | ||
} | ||
const proxy = !(0, _shared.isProduction)() ? deepProxy(obj, traps) : obj; | ||
@@ -123,3 +106,2 @@ return { | ||
} | ||
try { | ||
@@ -131,12 +113,12 @@ setIsUpdateable(proxy, true); | ||
} | ||
return proxy; | ||
}, | ||
unwrap: entry => entry ? //simply clone the provided object (if its a proxy) | ||
unwrapProxy(entry) : //unwrap entire proxy state | ||
unwrap: entry => entry ? | ||
//simply clone the provided object (if its a proxy) | ||
unwrapProxy(entry) : | ||
//unwrap entire proxy state | ||
(0, _utils.isProxy)(proxy) ? unwrapProxy(proxy) : proxy | ||
}; | ||
}; | ||
var _default = createState; | ||
exports.default = _default; |
@@ -36,9 +36,5 @@ "use strict"; | ||
}); | ||
var _createState = _interopRequireWildcard(require("./createState")); | ||
var _utils = require("./utils"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
@@ -7,16 +7,10 @@ "use strict"; | ||
exports.isProxy = exports.isProxiable = void 0; | ||
var _consts = require("./consts"); | ||
var _shared = require("@rpldy/shared"); | ||
const isProxy = obj => !(0, _shared.isProduction)() && !!obj && !!~Object.getOwnPropertySymbols(obj).indexOf(_consts.PROXY_SYM); | ||
const isProxy = obj => !(0, _shared.isProduction)() && !!obj && !!~Object.getOwnPropertySymbols(obj).indexOf(_consts.PROXY_SYM); //check if object is File or react-native file object (it wont by instanceof File in react-native) | ||
//check if object is File or react-native file object (it wont by instanceof File in react-native) | ||
exports.isProxy = isProxy; | ||
const isNativeFile = obj => (0, _shared.hasWindow)() && obj instanceof File || obj.name && obj.size && obj.uri; | ||
const isProxiable = obj => Array.isArray(obj) || (0, _shared.isPlainObject)(obj) && !isNativeFile(obj); | ||
exports.isProxiable = isProxiable; |
@@ -8,5 +8,3 @@ import { clone, getMerge, isProduction } from "@rpldy/shared"; | ||
}); | ||
const getIsUpdateable = proxy => isProduction() ? true : proxy[STATE_SYM].isUpdateable; | ||
const setIsUpdateable = (proxy, value) => { | ||
@@ -17,6 +15,4 @@ if (!isProduction()) { | ||
}; | ||
const deepProxy = (obj, traps) => { | ||
let proxy; | ||
if (isProxiable(obj)) { | ||
@@ -27,3 +23,2 @@ if (!isProxy(obj)) { | ||
} | ||
Object.keys(obj).forEach(key => { | ||
@@ -33,7 +28,6 @@ obj[key] = deepProxy(obj[key], traps); | ||
} | ||
return proxy || obj; | ||
}; | ||
const unwrapProxy = proxy => isProxy(proxy) ? clone(proxy, mergeWithSymbols) : proxy; | ||
const unwrapProxy = proxy => isProxy(proxy) ? clone(proxy, mergeWithSymbols) : proxy; | ||
/** | ||
@@ -54,4 +48,2 @@ * deep proxies an object so it is only updateable through an update callback. | ||
*/ | ||
const createState = obj => { | ||
@@ -63,3 +55,2 @@ const traps = { | ||
} | ||
return true; | ||
@@ -80,7 +71,5 @@ }, | ||
} | ||
return true; | ||
} | ||
}; | ||
if (!isProduction() && !isProxy(obj)) { | ||
@@ -94,3 +83,2 @@ Object.defineProperty(obj, STATE_SYM, { | ||
} | ||
const proxy = !isProduction() ? deepProxy(obj, traps) : obj; | ||
@@ -103,3 +91,2 @@ return { | ||
} | ||
try { | ||
@@ -111,12 +98,12 @@ setIsUpdateable(proxy, true); | ||
} | ||
return proxy; | ||
}, | ||
unwrap: entry => entry ? //simply clone the provided object (if its a proxy) | ||
unwrapProxy(entry) : //unwrap entire proxy state | ||
unwrap: entry => entry ? | ||
//simply clone the provided object (if its a proxy) | ||
unwrapProxy(entry) : | ||
//unwrap entire proxy state | ||
isProxy(proxy) ? unwrapProxy(proxy) : proxy | ||
}; | ||
}; | ||
export default createState; | ||
export { isProxy, unwrapProxy as unwrap }; |
import { PROXY_SYM } from "./consts"; | ||
import { isPlainObject, isProduction, hasWindow } from "@rpldy/shared"; | ||
const isProxy = obj => !isProduction() && !!obj && !!~Object.getOwnPropertySymbols(obj).indexOf(PROXY_SYM); | ||
const isProxy = obj => !isProduction() && !!obj && !!~Object.getOwnPropertySymbols(obj).indexOf(PROXY_SYM); //check if object is File or react-native file object (it wont by instanceof File in react-native) | ||
//check if object is File or react-native file object (it wont by instanceof File in react-native) | ||
const isNativeFile = obj => hasWindow() && obj instanceof File || obj.name && obj.size && obj.uri; | ||
const isProxiable = obj => Array.isArray(obj) || isPlainObject(obj) && !isNativeFile(obj); | ||
export { isProxy, isProxiable }; |
{ | ||
"version": "1.3.1", | ||
"version": "1.4.0-rc.0", | ||
"name": "@rpldy/simple-state", | ||
@@ -26,6 +26,6 @@ "description": "deep proxy object, so it's only updateable through an update method", | ||
"dependencies": { | ||
"@rpldy/shared": "^1.3.1" | ||
"@rpldy/shared": "^1.4.0-rc.0" | ||
}, | ||
"devDependencies": { | ||
"flow-bin": "^0.182.0" | ||
"flow-bin": "^0.199.1" | ||
}, | ||
@@ -35,3 +35,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "8a2473ae6d9521c5f16f5ae525466075ac02fd1f" | ||
"gitHead": "96a9141aa17e74962f1606d836f8f9f5c4b7aef0" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
302
14646
1
Updated@rpldy/shared@^1.4.0-rc.0