Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-asset

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-asset - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

18

.size-snapshot.json
{
"index.js": {
"bundled": 2827,
"minified": 1300,
"gzipped": 575,
"bundled": 2688,
"minified": 1237,
"gzipped": 552,
"treeshaked": {
"rollup": {
"code": 14,
"import_statements": 14
"code": 38,
"import_statements": 38
},
"webpack": {
"code": 1843
"code": 1831
}

@@ -17,6 +17,6 @@ }

"index.cjs.js": {
"bundled": 6129,
"minified": 3361,
"gzipped": 1278
"bundled": 6225,
"minified": 3486,
"gzipped": 1310
}
}

@@ -6,3 +6,8 @@ 'use strict';

var react = require('react');
var deepEqual = require('fast-deep-equal');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var deepEqual__default = /*#__PURE__*/_interopDefaultLegacy(deepEqual);
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }

@@ -15,8 +20,2 @@

var deepEqual = function deepEqual(a, b) {
return a === b || a.length === b.length && a.every(function (arg, index) {
if (Array.isArray(arg) && Array.isArray(b[index])) return deepEqual(arg, b[index]);else return arg === b[index];
});
};
function handleAsset(fn, cache, args, lifespan, preload) {

@@ -35,3 +34,3 @@ if (lifespan === void 0) {

// Find a match
if (deepEqual(args, _entry.args)) {
if (deepEqual__default['default'](args, _entry.args)) {
// If we're pre-loading and the element is present, just return

@@ -57,3 +56,3 @@ if (preload) return; // If an error occurred, throw

})["catch"](function (e) {
return entry.error = e;
return entry.error = e != null ? e : 'unknown error';
}).then(function () {

@@ -79,3 +78,3 @@ if (lifespan > 0) {

var entry = cache.find(function (entry) {
return deepEqual(args, entry.args);
return deepEqual__default['default'](args, entry.args);
});

@@ -130,3 +129,3 @@

return (_cache$find = cache.find(function (entry) {
return deepEqual(args, entry.args);
return deepEqual__default['default'](args, entry.args);
})) == null ? void 0 : _cache$find.response;

@@ -173,3 +172,3 @@ }

return (_globalCache$find = globalCache.find(function (entry) {
return deepEqual(args, entry.args);
return deepEqual__default['default'](args, entry.args);
})) == null ? void 0 : _globalCache$find.response;

@@ -176,0 +175,0 @@ };

import { useMemo } from 'react';
import deepEqual from 'fast-deep-equal';
const globalCache = [];
const deepEqual = (a, b) => a === b || a.length === b.length && a.every((arg, index) => {
if (Array.isArray(arg) && Array.isArray(b[index])) return deepEqual(arg, b[index]);else return arg === b[index];
});
function handleAsset(fn, cache, args, lifespan = 0, preload = false) {

@@ -30,3 +27,3 @@ for (const entry of cache) {

// This is for promises that do not return results (delays for instance)
.then(response => entry.response = response != null ? response : true).catch(e => entry.error = e).then(() => {
.then(response => entry.response = response != null ? response : true).catch(e => entry.error = e != null ? e : 'unknown error').then(() => {
if (lifespan > 0) {

@@ -33,0 +30,0 @@ setTimeout(() => {

{
"name": "use-asset",
"version": "1.0.1",
"version": "1.0.2",
"description": "A data fetching strategy for React Suspense",

@@ -73,3 +73,6 @@ "main": "dist/index.cjs",

"react": ">=17.0"
},
"dependencies": {
"fast-deep-equal": "^3.1.3"
}
}
import { useMemo } from 'react'
import deepEqual from 'fast-deep-equal'

@@ -13,9 +14,2 @@ type PromiseCache<Response, Args extends any[]> = {

const globalCache: PromiseCache<any, any[]>[] = []
const deepEqual = (a: any[], b: any[]): boolean =>
a === b ||
(a.length === b.length &&
a.every((arg, index) => {
if (Array.isArray(arg) && Array.isArray(b[index])) return deepEqual(arg, b[index])
else return arg === b[index]
}))

@@ -52,3 +46,3 @@ function handleAsset<Response, Args extends any[]>(

.then((response) => (entry.response = (response ?? true) as Response))
.catch((e) => (entry.error = e))
.catch((e) => (entry.error = e ?? 'unknown error'))
.then(() => {

@@ -55,0 +49,0 @@ if (lifespan > 0) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc