Skip to content

Commit

Permalink
chore: expose UseAssetsStatus values
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Aug 1, 2024
1 parent b33e897 commit d83e974
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/constants/UseAssetsStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const UseAssetsStatus = {
ERROR: 'error',
PENDING: 'pending',
SUCCESS: 'success',
};
5 changes: 1 addition & 4 deletions src/hooks/useAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import type { ErrorCallback } from '../typedefs/ErrorCallback.ts';

const errorCache: Map<UnresolvedAsset | string, AssetRetryState> = new Map();

/**
* Loads assets, returning a hash of assets once they're loaded.
* @deprecated Use `useAssets` instead.
*/
/** @deprecated Use `useAssets` instead. */
export function useAsset<T>(
/** @description Asset options. */
options: (UnresolvedAsset<T> & AssetRetryOptions) | string,
Expand Down
11 changes: 5 additions & 6 deletions src/hooks/useAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
Cache,
} from 'pixi.js';
import { useState } from 'react';
import { UseAssetsStatus } from '../constants/UseAssetsStatus.ts';
import { getAssetKey } from '../helpers/getAssetKey.ts';
import { UseAssetsStatus } from '../typedefs/UseAssetsStatus.ts';

import type { AssetRetryState } from '../typedefs/AssetRetryState.ts';
import type { UnresolvedAsset } from '../typedefs/UnresolvedAsset.ts';
Expand Down Expand Up @@ -32,7 +32,7 @@ export function useAssets<T = any>(
isError: false,
isPending: true,
isSuccess: false,
status: UseAssetsStatus.Pending,
status: UseAssetsStatus.PENDING,
});

if (typeof window === 'undefined')
Expand Down Expand Up @@ -67,12 +67,11 @@ export function useAssets<T = any>(
isError: true,
isPending: false,
isSuccess: false,
status: UseAssetsStatus.Error,
status: UseAssetsStatus.ERROR,
}));
}

Assets
.load<T>(assets, (progressValue) =>
Assets.load<T>(assets, (progressValue) =>
{
if (typeof onProgress === 'function')
{
Expand All @@ -90,7 +89,7 @@ export function useAssets<T = any>(
isError: false,
isPending: false,
isSuccess: true,
status: UseAssetsStatus.Success,
status: UseAssetsStatus.SUCCESS,
}));
})
.catch((error) =>
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Be aware that you are using a beta version of Pixi React.
`);

export { Application } from './components/Application.ts';
export { UseAssetsStatus } from './constants/UseAssetsStatus.ts';
export { createRoot } from './core/createRoot.ts';
export * from './global.ts';
export { extend } from './helpers/extend.ts';
Expand Down
6 changes: 0 additions & 6 deletions src/typedefs/UseAssetsStatus.ts

This file was deleted.

0 comments on commit d83e974

Please sign in to comment.