chore: use #client alias (#10974)

pull/10977/head
Rich Harris 5 months ago committed by GitHub
parent f303d82043
commit 293f905a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -22,11 +22,11 @@ function run_tasks(now) {
/**
* Creates a new task that runs on each raf frame
* until it returns a falsy value or is aborted
* @param {import('./types.js').TaskCallback} callback
* @returns {import('./types.js').Task}
* @param {import('#client').TaskCallback} callback
* @returns {import('#client').Task}
*/
export function loop(callback) {
/** @type {import('./types.js').TaskEntry} */
/** @type {import('#client').TaskEntry} */
let task;
if (raf.tasks.size === 0) {

@ -22,13 +22,13 @@ import { UNINITIALIZED } from '../../constants.js';
* @param {T} value
* @param {boolean} [immutable]
* @param {Set<Function> | null} [owners]
* @returns {import('./types.js').ProxyStateObject<T> | T}
* @returns {import('#client').ProxyStateObject<T> | T}
*/
export function proxy(value, immutable = true, owners) {
if (typeof value === 'object' && value != null && !is_frozen(value)) {
// If we have an existing proxy, return it...
if (STATE_SYMBOL in value) {
const metadata = /** @type {import('./types.js').ProxyMetadata<T>} */ (value[STATE_SYMBOL]);
const metadata = /** @type {import('#client').ProxyMetadata<T>} */ (value[STATE_SYMBOL]);
// ...unless the proxy belonged to a different object, because
// someone copied the state symbol using `Reflect.ownKeys(...)`
if (metadata.t === value || metadata.p === value) {
@ -53,7 +53,7 @@ export function proxy(value, immutable = true, owners) {
const proxy = new Proxy(value, state_proxy_handler);
define_property(value, STATE_SYMBOL, {
value: /** @type {import('./types.js').ProxyMetadata} */ ({
value: /** @type {import('#client').ProxyMetadata} */ ({
s: new Map(),
v: source(0),
a: is_array(value),
@ -86,7 +86,7 @@ export function proxy(value, immutable = true, owners) {
}
/**
* @template {import('./types.js').ProxyStateObject} T
* @template {import('#client').ProxyStateObject} T
* @param {T} value
* @param {Map<T, Record<string | symbol, any>>} already_unwrapped
* @returns {Record<string | symbol, any>}
@ -138,23 +138,23 @@ function unwrap(value, already_unwrapped) {
*/
export function unstate(value) {
return /** @type {T} */ (
unwrap(/** @type {import('./types.js').ProxyStateObject} */ (value), new Map())
unwrap(/** @type {import('#client').ProxyStateObject} */ (value), new Map())
);
}
/**
* @param {import('./types.js').Source<number>} signal
* @param {import('#client').Source<number>} signal
* @param {1 | -1} [d]
*/
function update_version(signal, d = 1) {
set(signal, signal.v + d);
}
/** @type {ProxyHandler<import('./types.js').ProxyStateObject<any>>} */
/** @type {ProxyHandler<import('#client').ProxyStateObject<any>>} */
const state_proxy_handler = {
defineProperty(target, prop, descriptor) {
if (descriptor.value) {
/** @type {import('./types.js').ProxyMetadata} */
/** @type {import('#client').ProxyMetadata} */
const metadata = target[STATE_SYMBOL];
const s = metadata.s.get(prop);
@ -165,7 +165,7 @@ const state_proxy_handler = {
},
deleteProperty(target, prop) {
/** @type {import('./types.js').ProxyMetadata} */
/** @type {import('#client').ProxyMetadata} */
const metadata = target[STATE_SYMBOL];
const s = metadata.s.get(prop);
const is_array = metadata.a;
@ -198,7 +198,7 @@ const state_proxy_handler = {
return Reflect.get(target, STATE_SYMBOL);
}
/** @type {import('./types.js').ProxyMetadata} */
/** @type {import('#client').ProxyMetadata} */
const metadata = target[STATE_SYMBOL];
let s = metadata.s.get(prop);
@ -229,7 +229,7 @@ const state_proxy_handler = {
getOwnPropertyDescriptor(target, prop) {
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
if (descriptor && 'value' in descriptor) {
/** @type {import('./types.js').ProxyMetadata} */
/** @type {import('#client').ProxyMetadata} */
const metadata = target[STATE_SYMBOL];
const s = metadata.s.get(prop);
@ -245,7 +245,7 @@ const state_proxy_handler = {
if (prop === STATE_SYMBOL) {
return true;
}
/** @type {import('./types.js').ProxyMetadata} */
/** @type {import('#client').ProxyMetadata} */
const metadata = target[STATE_SYMBOL];
const has = Reflect.has(target, prop);
@ -266,7 +266,7 @@ const state_proxy_handler = {
},
set(target, prop, value, receiver) {
/** @type {import('./types.js').ProxyMetadata} */
/** @type {import('#client').ProxyMetadata} */
const metadata = target[STATE_SYMBOL];
let s = metadata.s.get(prop);
// If we haven't yet created a source for this property, we need to ensure
@ -329,7 +329,7 @@ const state_proxy_handler = {
},
ownKeys(target) {
/** @type {import('./types.js').ProxyMetadata} */
/** @type {import('#client').ProxyMetadata} */
const metadata = target[STATE_SYMBOL];
get(metadata.v);

@ -6,7 +6,7 @@ const request_animation_frame = is_client ? requestAnimationFrame : noop;
const now = is_client ? () => performance.now() : () => Date.now();
/** @type {import('./types.js').Raf} */
/** @type {import('#client').Raf} */
export const raf = {
tick: /** @param {any} _ */ (_) => request_animation_frame(_),
now: () => now(),

Loading…
Cancel
Save