@wordpress/private-apis
Advanced tools
Comparing version 1.13.0 to 1.13.1-next.a9f418477.0
@@ -95,6 +95,7 @@ /** | ||
} | ||
if (!(__private in object)) { | ||
object[__private] = {}; | ||
const _object = object; | ||
if (!(__private in _object)) { | ||
_object[__private] = {}; | ||
} | ||
lockedData.set(object[__private], privateData); | ||
lockedData.set(_object[__private], privateData); | ||
} | ||
@@ -129,6 +130,7 @@ | ||
} | ||
if (!(__private in object)) { | ||
const _object = object; | ||
if (!(__private in _object)) { | ||
throw new Error('Cannot unlock an object that was not locked before. '); | ||
} | ||
return lockedData.get(object[__private]); | ||
return lockedData.get(_object[__private]); | ||
} | ||
@@ -135,0 +137,0 @@ const lockedData = new WeakMap(); |
@@ -44,3 +44,3 @@ /** | ||
*/ | ||
declare function lock(object: Record<symbol, WeakKey>, privateData: unknown): void; | ||
declare function lock(object: unknown, privateData: unknown): void; | ||
/** | ||
@@ -69,3 +69,3 @@ * Unlocks the private data bound to an object. | ||
*/ | ||
declare function unlock(object: Record<symbol, WeakKey>): any; | ||
declare function unlock<T = any>(object: unknown): T; | ||
/** | ||
@@ -72,0 +72,0 @@ * Private function to allow the unit tests to allow |
@@ -105,6 +105,7 @@ "use strict"; | ||
} | ||
if (!(__private in object)) { | ||
object[__private] = {}; | ||
const _object = object; | ||
if (!(__private in _object)) { | ||
_object[__private] = {}; | ||
} | ||
lockedData.set(object[__private], privateData); | ||
lockedData.set(_object[__private], privateData); | ||
} | ||
@@ -139,6 +140,7 @@ | ||
} | ||
if (!(__private in object)) { | ||
const _object = object; | ||
if (!(__private in _object)) { | ||
throw new Error('Cannot unlock an object that was not locked before. '); | ||
} | ||
return lockedData.get(object[__private]); | ||
return lockedData.get(_object[__private]); | ||
} | ||
@@ -145,0 +147,0 @@ const lockedData = new WeakMap(); |
{ | ||
"name": "@wordpress/private-apis", | ||
"version": "1.13.0", | ||
"version": "1.13.1-next.a9f418477.0", | ||
"description": "Internal experimental APIs for WordPress core.", | ||
@@ -38,3 +38,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "cce81c13739c2a8b53d91df90c4f037cb68c2665" | ||
"gitHead": "c1a8f3e9cada3b7d8342d1d2595c2dac0433111d" | ||
} |
@@ -140,10 +140,12 @@ /** | ||
*/ | ||
function lock( object: Record< symbol, WeakKey >, privateData: unknown ) { | ||
function lock( object: unknown, privateData: unknown ) { | ||
if ( ! object ) { | ||
throw new Error( 'Cannot lock an undefined object.' ); | ||
} | ||
if ( ! ( __private in object ) ) { | ||
object[ __private ] = {}; | ||
const _object = object as Record< symbol, WeakKey >; | ||
if ( ! ( __private in _object ) ) { | ||
_object[ __private ] = {}; | ||
} | ||
lockedData.set( object[ __private ], privateData ); | ||
lockedData.set( _object[ __private ], privateData ); | ||
} | ||
@@ -174,7 +176,9 @@ | ||
*/ | ||
function unlock( object: Record< symbol, WeakKey > ) { | ||
function unlock< T = any >( object: unknown ): T { | ||
if ( ! object ) { | ||
throw new Error( 'Cannot unlock an undefined object.' ); | ||
} | ||
if ( ! ( __private in object ) ) { | ||
const _object = object as Record< symbol, WeakKey >; | ||
if ( ! ( __private in _object ) ) { | ||
throw new Error( | ||
@@ -185,3 +189,3 @@ 'Cannot unlock an object that was not locked before. ' | ||
return lockedData.get( object[ __private ] ); | ||
return lockedData.get( _object[ __private ] ); | ||
} | ||
@@ -188,0 +192,0 @@ |
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
Sorry, the diff of this file is not supported yet
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
115037
952
1