@wordpress/interactivity
Advanced tools
Comparing version 6.8.2 to 6.9.0
@@ -112,3 +112,3 @@ // eslint-disable-next-line eslint-comments/disable-enable-pair | ||
if (typeof resolvedStore === 'undefined') { | ||
resolvedStore = store(namespace, undefined, { | ||
resolvedStore = store(namespace, {}, { | ||
lock: universalUnlock | ||
@@ -115,0 +115,0 @@ }); |
@@ -106,2 +106,10 @@ /** | ||
// Overload for when the types are inferred. | ||
// Overload for when types are passed via generics and they contain state. | ||
// Overload for when types are passed via generics and they don't contain state. | ||
// Overload for when types are divided into multiple parts. | ||
export function store(namespace, { | ||
@@ -108,0 +116,0 @@ state = {}, |
@@ -62,2 +62,21 @@ export declare const stores: Map<any, any>; | ||
} | ||
type Prettify<T> = { | ||
[K in keyof T]: T[K]; | ||
} & {}; | ||
type DeepPartial<T> = T extends object ? { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
} : T; | ||
type DeepPartialState<T extends { | ||
state: object; | ||
}> = Omit<T, 'state'> & { | ||
state?: DeepPartial<T['state']>; | ||
}; | ||
type ConvertGeneratorToPromise<T> = T extends (...args: infer A) => Generator<any, infer R, any> ? (...args: A) => Promise<R> : never; | ||
type ConvertGeneratorsToPromises<T> = { | ||
[K in keyof T]: T[K] extends (...args: any[]) => any ? ConvertGeneratorToPromise<T[K]> extends never ? T[K] : ConvertGeneratorToPromise<T[K]> : T[K] extends object ? Prettify<ConvertGeneratorsToPromises<T[K]>> : T[K]; | ||
}; | ||
type ConvertPromiseToGenerator<T> = T extends (...args: infer A) => Promise<infer R> ? (...args: A) => Generator<any, R, any> : never; | ||
type ConvertPromisesToGenerators<T> = { | ||
[K in keyof T]: T[K] extends (...args: any[]) => any ? ConvertPromiseToGenerator<T[K]> extends never ? T[K] : ConvertPromiseToGenerator<T[K]> : T[K] extends object ? Prettify<ConvertPromisesToGenerators<T[K]>> : T[K]; | ||
}; | ||
export declare const universalUnlock = "I acknowledge that using a private store means my plugin will inevitably break on the next store release."; | ||
@@ -109,4 +128,8 @@ /** | ||
*/ | ||
export declare function store<S extends object = {}>(namespace: string, storePart?: S, options?: StoreOptions): S; | ||
export declare function store<T extends object>(namespace: string, storePart?: T, options?: StoreOptions): T; | ||
export declare function store<T extends object>(namespace: string, storePart: T, options?: StoreOptions): Prettify<ConvertGeneratorsToPromises<T>>; | ||
export declare function store<T extends { | ||
state: object; | ||
}>(namespace: string, storePart: ConvertPromisesToGenerators<DeepPartialState<T>>, options?: StoreOptions): Prettify<ConvertGeneratorsToPromises<T>>; | ||
export declare function store<T extends object>(namespace: string, storePart: ConvertPromisesToGenerators<T>, options?: StoreOptions): Prettify<ConvertGeneratorsToPromises<T>>; | ||
export declare function store<T extends object>(namespace: string, storePart: ConvertPromisesToGenerators<DeepPartial<T>>, options?: StoreOptions): Prettify<ConvertGeneratorsToPromises<T>>; | ||
export declare const parseServerData: (dom?: Document) => any; | ||
@@ -113,0 +136,0 @@ export declare const populateServerData: (data?: { |
@@ -121,3 +121,3 @@ "use strict"; | ||
if (typeof resolvedStore === 'undefined') { | ||
resolvedStore = (0, _store.store)(namespace, undefined, { | ||
resolvedStore = (0, _store.store)(namespace, {}, { | ||
lock: _store.universalUnlock | ||
@@ -124,0 +124,0 @@ }); |
@@ -118,2 +118,10 @@ "use strict"; | ||
// Overload for when the types are inferred. | ||
// Overload for when types are passed via generics and they contain state. | ||
// Overload for when types are passed via generics and they don't contain state. | ||
// Overload for when types are divided into multiple parts. | ||
function store(namespace, { | ||
@@ -120,0 +128,0 @@ state = {}, |
@@ -5,2 +5,4 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> | ||
## 6.9.0 (2024-10-03) | ||
## 6.8.0 (2024-09-19) | ||
@@ -10,2 +12,3 @@ | ||
- Improve TypeScript support for generators ([#64577](https://github.com/WordPress/gutenberg/pull/64577)). | ||
- Refactor internal context proxies implementation ([#64713](https://github.com/WordPress/gutenberg/pull/64713)). | ||
@@ -12,0 +15,0 @@ |
{ | ||
"name": "@wordpress/interactivity", | ||
"version": "6.8.2", | ||
"version": "6.9.0", | ||
"description": "Package that provides a standard and simple way to handle the frontend interactivity of Gutenberg blocks.", | ||
@@ -40,3 +40,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "3686e926862c54c6326fe97277e0a19f8bbfafdd" | ||
"gitHead": "2e5495c635910cb34bfaca3c6258d2e989f66214" | ||
} |
@@ -87,2 +87,38 @@ /** | ||
type Prettify< T > = { [ K in keyof T ]: T[ K ] } & {}; | ||
type DeepPartial< T > = T extends object | ||
? { [ P in keyof T ]?: DeepPartial< T[ P ] > } | ||
: T; | ||
type DeepPartialState< T extends { state: object } > = Omit< T, 'state' > & { | ||
state?: DeepPartial< T[ 'state' ] >; | ||
}; | ||
type ConvertGeneratorToPromise< T > = T extends ( | ||
...args: infer A | ||
) => Generator< any, infer R, any > | ||
? ( ...args: A ) => Promise< R > | ||
: never; | ||
type ConvertGeneratorsToPromises< T > = { | ||
[ K in keyof T ]: T[ K ] extends ( ...args: any[] ) => any | ||
? ConvertGeneratorToPromise< T[ K ] > extends never | ||
? T[ K ] | ||
: ConvertGeneratorToPromise< T[ K ] > | ||
: T[ K ] extends object | ||
? Prettify< ConvertGeneratorsToPromises< T[ K ] > > | ||
: T[ K ]; | ||
}; | ||
type ConvertPromiseToGenerator< T > = T extends ( | ||
...args: infer A | ||
) => Promise< infer R > | ||
? ( ...args: A ) => Generator< any, R, any > | ||
: never; | ||
type ConvertPromisesToGenerators< T > = { | ||
[ K in keyof T ]: T[ K ] extends ( ...args: any[] ) => any | ||
? ConvertPromiseToGenerator< T[ K ] > extends never | ||
? T[ K ] | ||
: ConvertPromiseToGenerator< T[ K ] > | ||
: T[ K ] extends object | ||
? Prettify< ConvertPromisesToGenerators< T[ K ] > > | ||
: T[ K ]; | ||
}; | ||
export const universalUnlock = | ||
@@ -136,14 +172,31 @@ 'I acknowledge that using a private store means my plugin will inevitably break on the next store release.'; | ||
*/ | ||
export function store< S extends object = {} >( | ||
// Overload for when the types are inferred. | ||
export function store< T extends object >( | ||
namespace: string, | ||
storePart?: S, | ||
storePart: T, | ||
options?: StoreOptions | ||
): S; | ||
): Prettify< ConvertGeneratorsToPromises< T > >; | ||
// Overload for when types are passed via generics and they contain state. | ||
export function store< T extends { state: object } >( | ||
namespace: string, | ||
storePart: ConvertPromisesToGenerators< DeepPartialState< T > >, | ||
options?: StoreOptions | ||
): Prettify< ConvertGeneratorsToPromises< T > >; | ||
// Overload for when types are passed via generics and they don't contain state. | ||
export function store< T extends object >( | ||
namespace: string, | ||
storePart?: T, | ||
storePart: ConvertPromisesToGenerators< T >, | ||
options?: StoreOptions | ||
): T; | ||
): Prettify< ConvertGeneratorsToPromises< T > >; | ||
// Overload for when types are divided into multiple parts. | ||
export function store< T extends object >( | ||
namespace: string, | ||
storePart: ConvertPromisesToGenerators< DeepPartial< T > >, | ||
options?: StoreOptions | ||
): Prettify< ConvertGeneratorsToPromises< T > >; | ||
export function store( | ||
@@ -150,0 +203,0 @@ namespace: string, |
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
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
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
739073
133
10332