AssetRegistry.js 858 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @flow strict
  8. * @format
  9. */
  10. 'use strict';
  11. export type PackagerAsset = {
  12. +__packager_asset: boolean,
  13. +fileSystemLocation: string,
  14. +httpServerLocation: string,
  15. +width: ?number,
  16. +height: ?number,
  17. +scales: Array<number>,
  18. +hash: string,
  19. +name: string,
  20. +type: string,
  21. ...
  22. };
  23. const assets: Array<PackagerAsset> = [];
  24. function registerAsset(asset: PackagerAsset): number {
  25. // `push` returns new array length, so the first asset will
  26. // get id 1 (not 0) to make the value truthy
  27. return assets.push(asset);
  28. }
  29. function getAssetByID(assetId: number): PackagerAsset {
  30. return assets[assetId - 1];
  31. }
  32. module.exports = {registerAsset, getAssetByID};