@pixi/react
Advanced tools
Comparing version 8.0.0-beta.15 to 8.0.0-beta.16
@@ -1261,13 +1261,24 @@ 'use strict'; | ||
} | ||
function resolveAssets(assets) { | ||
const assetKeys = assets.map((asset) => getAssetKey(asset)); | ||
const resolvedAssetsDictionary = pixi_js.Assets.get(assetKeys); | ||
return { | ||
assets: assets.map((_asset, index) => resolvedAssetsDictionary[index]), | ||
isError: false, | ||
isPending: false, | ||
isSuccess: true, | ||
status: UseAssetsStatus.SUCCESS | ||
}; | ||
} | ||
function useAssets(assets, options = {}) { | ||
const [state, setState] = react.useState({ | ||
assets: Array(assets.length).fill(void 0), | ||
isError: false, | ||
isPending: true, | ||
isSuccess: false, | ||
status: UseAssetsStatus.PENDING | ||
}); | ||
if (typeof window === "undefined") { | ||
return state; | ||
} | ||
const allAssetsAreLoaded = assets.every((asset) => assetsLoadedTest$1(asset)); | ||
const [state, setState] = react.useState( | ||
typeof window !== "undefined" && allAssetsAreLoaded ? resolveAssets(assets) : { | ||
assets: Array(assets.length).fill(void 0), | ||
isError: false, | ||
isPending: true, | ||
isSuccess: false, | ||
status: UseAssetsStatus.PENDING | ||
} | ||
); | ||
const { | ||
@@ -1279,3 +1290,2 @@ maxRetries = 3, | ||
} = options; | ||
const allAssetsAreLoaded = assets.some(assetsLoadedTest$1); | ||
if (!allAssetsAreLoaded) { | ||
@@ -1301,11 +1311,5 @@ let cachedState = errorCache$1.get(assets); | ||
}).then(() => { | ||
const assetKeys = assets.map((asset) => getAssetKey(asset)); | ||
const resolvedAssetsDictionary = pixi_js.Assets.get(assetKeys); | ||
setState((previousState) => ({ | ||
...previousState, | ||
assets: assets.map((_asset, index) => resolvedAssetsDictionary[index]), | ||
isError: false, | ||
isPending: false, | ||
isSuccess: true, | ||
status: UseAssetsStatus.SUCCESS | ||
...resolveAssets(assets) | ||
})); | ||
@@ -1312,0 +1316,0 @@ }).catch((error) => { |
@@ -13,13 +13,24 @@ 'use strict'; | ||
} | ||
function resolveAssets(assets) { | ||
const assetKeys = assets.map((asset) => getAssetKey.getAssetKey(asset)); | ||
const resolvedAssetsDictionary = pixi_js.Assets.get(assetKeys); | ||
return { | ||
assets: assets.map((_asset, index) => resolvedAssetsDictionary[index]), | ||
isError: false, | ||
isPending: false, | ||
isSuccess: true, | ||
status: UseAssetsStatus.UseAssetsStatus.SUCCESS | ||
}; | ||
} | ||
function useAssets(assets, options = {}) { | ||
const [state, setState] = react.useState({ | ||
assets: Array(assets.length).fill(void 0), | ||
isError: false, | ||
isPending: true, | ||
isSuccess: false, | ||
status: UseAssetsStatus.UseAssetsStatus.PENDING | ||
}); | ||
if (typeof window === "undefined") { | ||
return state; | ||
} | ||
const allAssetsAreLoaded = assets.every((asset) => assetsLoadedTest(asset)); | ||
const [state, setState] = react.useState( | ||
typeof window !== "undefined" && allAssetsAreLoaded ? resolveAssets(assets) : { | ||
assets: Array(assets.length).fill(void 0), | ||
isError: false, | ||
isPending: true, | ||
isSuccess: false, | ||
status: UseAssetsStatus.UseAssetsStatus.PENDING | ||
} | ||
); | ||
const { | ||
@@ -31,3 +42,2 @@ maxRetries = 3, | ||
} = options; | ||
const allAssetsAreLoaded = assets.some(assetsLoadedTest); | ||
if (!allAssetsAreLoaded) { | ||
@@ -53,11 +63,5 @@ let cachedState = errorCache.get(assets); | ||
}).then(() => { | ||
const assetKeys = assets.map((asset) => getAssetKey.getAssetKey(asset)); | ||
const resolvedAssetsDictionary = pixi_js.Assets.get(assetKeys); | ||
setState((previousState) => ({ | ||
...previousState, | ||
assets: assets.map((_asset, index) => resolvedAssetsDictionary[index]), | ||
isError: false, | ||
isPending: false, | ||
isSuccess: true, | ||
status: UseAssetsStatus.UseAssetsStatus.SUCCESS | ||
...resolveAssets(assets) | ||
})); | ||
@@ -64,0 +68,0 @@ }).catch((error) => { |
{ | ||
"name": "@pixi/react", | ||
"version": "8.0.0-beta.15", | ||
"version": "8.0.0-beta.16", | ||
"description": "Write PixiJS applications using React declarative style.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
656011
6433