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

artemis-client

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

artemis-client - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

105

dist/artemis-client.cjs.development.js

@@ -25,2 +25,30 @@ 'use strict';

var startFetch = function startFetch(url, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
variables = _ref.variables;
var abortController = new AbortController();
console.log('ignoring variables because reasons', {
variables: variables
});
var promise = fetch(url, {
signal: abortController.signal
}).then(function (resp) {
try {
return Promise.resolve(resp.json());
} catch (e) {
return Promise.reject(e);
}
});
var abort = function abort() {
return abortController.abort();
};
return {
promise: promise,
abort: abort
};
};
var useQuery = function useQuery(url, options) {

@@ -33,4 +61,4 @@ if (options === void 0) {

loading: true,
data: null,
error: null
data: undefined,
error: undefined
}),

@@ -40,48 +68,47 @@ state = _useState[0],

var _useState2 = react.useState(true),
reloadTrigger = _useState2[0],
setReload = _useState2[1];
var _useState2 = react.useState(options.variables),
variables = _useState2[0],
setVariables = _useState2[1];
var _useState3 = react.useState(options.variables),
variables = _useState3[0],
setVariables = _useState3[1];
react.useEffect(function () {
setVariables(options.variables);
return setVariables(options.variables);
}, [options.variables]);
react.useEffect(function () {
var abort = new AbortController();
fetch(url, {
signal: abort.signal
}).then(function (resp) {
try {
return Promise.resolve(resp.json()).then(function (data) {
setState({
loading: false,
error: null,
data: data
});
});
} catch (e) {
return Promise.reject(e);
}
})["catch"](function (error) {
var doFetch = function doFetch(vars) {
if (vars === void 0) {
vars = variables;
}
setState({
loading: true,
error: undefined,
data: state.data
});
var _startFetch = startFetch(url, {
variables: vars
}),
promise = _startFetch.promise,
abort = _startFetch.abort;
promise.then(function (data) {
setState({
loading: false,
error: undefined,
data: data
});
}, function (error) {
setState({
loading: false,
error: error,
data: null
data: state.data
});
});
return function () {
abort.abort();
};
}, [url, variables, reloadTrigger]);
var refetch = react.useCallback(function (variables) {
if (variables) {
setVariables(variables);
}
return abort;
};
setReload(!reloadTrigger);
}, [reloadTrigger]);
console.log(state);
react.useEffect(function () {
return doFetch();
}, [url, variables]);
var refetch = react.useCallback(doFetch, [url, variables]);
return _extends({}, state, {

@@ -88,0 +115,0 @@ refetch: refetch,

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}exports.useQuery=function(t,n){void 0===n&&(n={});var a=e.useState({loading:!0,data:null,error:null}),o=a[0],u=a[1],l=e.useState(!0),i=l[0],c=l[1],s=e.useState(n.variables),f=s[0],v=s[1];e.useEffect((function(){v(n.variables)}),[n.variables]),e.useEffect((function(){var e=new AbortController;return fetch(t,{signal:e.signal}).then((function(e){try{return Promise.resolve(e.json()).then((function(e){u({loading:!1,error:null,data:e})}))}catch(e){return Promise.reject(e)}})).catch((function(e){u({loading:!1,error:e,data:null})})),function(){e.abort()}}),[t,f,i]);var b=e.useCallback((function(e){e&&v(e),c(!i)}),[i]);return console.log(o),r({},o,{refetch:b,variables:f})};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("react");function e(){return(e=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var t in a)Object.prototype.hasOwnProperty.call(a,t)&&(r[t]=a[t])}return r}).apply(this,arguments)}exports.useQuery=function(a,t){void 0===t&&(t={});var n=r.useState({loading:!0,data:void 0,error:void 0}),o=n[0],i=n[1],s=r.useState(t.variables),u=s[0],c=s[1];r.useEffect((function(){return c(t.variables)}),[t.variables]);var l=function(r){void 0===r&&(r=u),i({loading:!0,error:void 0,data:o.data});var e=function(r,e){var a=(void 0===e?{}:e).variables,t=new AbortController;return console.log("ignoring variables because reasons",{variables:a}),{promise:fetch(r,{signal:t.signal}).then((function(r){try{return Promise.resolve(r.json())}catch(r){return Promise.reject(r)}})),abort:function(){return t.abort()}}}(a,{variables:r}),t=e.abort;return e.promise.then((function(r){i({loading:!1,error:void 0,data:r})}),(function(r){i({loading:!1,error:r,data:o.data})})),t};r.useEffect((function(){return l()}),[a,u]);var v=r.useCallback(l,[a,u]);return e({},o,{refetch:v,variables:u})};
//# sourceMappingURL=artemis-client.cjs.production.min.js.map

@@ -21,2 +21,30 @@ import { useState, useEffect, useCallback } from 'react';

var startFetch = function startFetch(url, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
variables = _ref.variables;
var abortController = new AbortController();
console.log('ignoring variables because reasons', {
variables: variables
});
var promise = fetch(url, {
signal: abortController.signal
}).then(function (resp) {
try {
return Promise.resolve(resp.json());
} catch (e) {
return Promise.reject(e);
}
});
var abort = function abort() {
return abortController.abort();
};
return {
promise: promise,
abort: abort
};
};
var useQuery = function useQuery(url, options) {

@@ -29,4 +57,4 @@ if (options === void 0) {

loading: true,
data: null,
error: null
data: undefined,
error: undefined
}),

@@ -36,48 +64,47 @@ state = _useState[0],

var _useState2 = useState(true),
reloadTrigger = _useState2[0],
setReload = _useState2[1];
var _useState2 = useState(options.variables),
variables = _useState2[0],
setVariables = _useState2[1];
var _useState3 = useState(options.variables),
variables = _useState3[0],
setVariables = _useState3[1];
useEffect(function () {
setVariables(options.variables);
return setVariables(options.variables);
}, [options.variables]);
useEffect(function () {
var abort = new AbortController();
fetch(url, {
signal: abort.signal
}).then(function (resp) {
try {
return Promise.resolve(resp.json()).then(function (data) {
setState({
loading: false,
error: null,
data: data
});
});
} catch (e) {
return Promise.reject(e);
}
})["catch"](function (error) {
var doFetch = function doFetch(vars) {
if (vars === void 0) {
vars = variables;
}
setState({
loading: true,
error: undefined,
data: state.data
});
var _startFetch = startFetch(url, {
variables: vars
}),
promise = _startFetch.promise,
abort = _startFetch.abort;
promise.then(function (data) {
setState({
loading: false,
error: undefined,
data: data
});
}, function (error) {
setState({
loading: false,
error: error,
data: null
data: state.data
});
});
return function () {
abort.abort();
};
}, [url, variables, reloadTrigger]);
var refetch = useCallback(function (variables) {
if (variables) {
setVariables(variables);
}
return abort;
};
setReload(!reloadTrigger);
}, [reloadTrigger]);
console.log(state);
useEffect(function () {
return doFetch();
}, [url, variables]);
var refetch = useCallback(doFetch, [url, variables]);
return _extends({}, state, {

@@ -84,0 +111,0 @@ refetch: refetch,

@@ -6,20 +6,8 @@ interface QueryOptions {

export declare const useQuery: <T extends any>(url: string, options?: QueryOptions) => {
refetch: (variables: any) => void;
refetch: (vars?: object | undefined) => () => void;
variables: object | undefined;
loading: false;
error: Error;
data: null;
} | {
refetch: (variables: any) => void;
variables: object | undefined;
loading: true;
error: null;
data: null;
} | {
refetch: (variables: any) => void;
variables: object | undefined;
loading: false;
error: null;
data: T;
loading: boolean;
error?: Error | undefined;
data?: T | undefined;
};
export {};
{
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -40,2 +40,4 @@ # Artemis Client

- Mutation
- query shouldn't update state twice on load
- refetch shouldn't update state if data didn't change

@@ -42,0 +44,0 @@ ## TSDX

@@ -8,18 +8,21 @@ import { useState, useEffect, useCallback } from 'react'

interface ErrorState {
loading: false
error: Error
data: null
interface LoadingState<T> {
loading: boolean
error?: Error
data?: T
}
interface LoadingState {
loading: true
error: null
data: null
}
const startFetch = (
url: string,
{ variables }: { variables?: object } = {}
) => {
const abortController = new AbortController()
console.log('ignoring variables because reasons', { variables })
const promise = fetch(url, {
signal: abortController.signal,
}).then(async resp => resp.json())
interface ValueState<T> {
loading: false
error: null
data: T
const abort = () => abortController.abort()
return { promise, abort }
}

@@ -31,52 +34,43 @@

) => {
const [state, setState] = useState<ErrorState | LoadingState | ValueState<T>>(
{
loading: true,
data: null,
error: null,
}
)
const [state, setState] = useState<LoadingState<T>>({
loading: true,
data: undefined,
error: undefined,
})
const [reloadTrigger, setReload] = useState(true)
const [variables, setVariables] = useState(options.variables)
useEffect(() => {
setVariables(options.variables)
}, [options.variables])
useEffect(() => setVariables(options.variables), [options.variables])
useEffect(() => {
const abort = new AbortController()
fetch(url, { signal: abort.signal })
.then(async resp => {
const data = await resp.json()
const doFetch = (vars = variables) => {
setState({
loading: true,
error: undefined,
data: state.data,
})
const { promise, abort } = startFetch(url, { variables: vars })
promise.then(
data => {
setState({
loading: false,
error: null,
error: undefined,
data,
})
})
.catch((error: Error) => {
},
(error: Error) => {
setState({
loading: false,
error,
data: null,
data: state.data,
})
})
}
)
return () => {
abort.abort()
}
}, [url, variables, reloadTrigger])
return abort
}
const refetch = useCallback(
variables => {
if (variables) {
setVariables(variables)
}
setReload(!reloadTrigger)
},
[reloadTrigger]
)
useEffect(() => doFetch(), [url, variables])
console.log(state)
const refetch = useCallback(doFetch, [url, variables])
return {

@@ -83,0 +77,0 @@ ...state,

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

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