Skip to content

Commit

Permalink
Merge pull request #186 from atomic-state/fixes/FetchConfig
Browse files Browse the repository at this point in the history
FIX(defaults):
  • Loading branch information
danybeltran authored May 29, 2024
2 parents 86c71f6 + 20735e8 commit a63c74b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-react",
"version": "3.5.3",
"version": "3.5.4",
"description": "React hooks for data fetching",
"main": "dist/index.js",
"scripts": {
Expand Down
24 changes: 6 additions & 18 deletions src/components/FetchConfigAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ export async function FetchConfigAsync(props: FetchContextType) {

const $data = $value.data ?? $value

if (!isDefined(valuesMemory.get(resolvedKey))) {
valuesMemory.set(resolvedKey, $data)
}
if (!isDefined(fetcherDefaults.get(resolvedKey))) {
fetcherDefaults.set(resolvedKey, $data)
}
valuesMemory.set(resolvedKey, $data)

if (!isDefined(cacheProvider.get(resolvedKey))) {
cacheProvider.set(resolvedKey, $data)
}
fetcherDefaults.set(resolvedKey, $data)

cacheProvider.set(resolvedKey, $data)
}

for (let defaultKey in defaults) {
Expand All @@ -42,15 +37,8 @@ export async function FetchConfigAsync(props: FetchContextType) {
})

if (isDefined(id)) {
if (!isDefined(valuesMemory.get(resolvedKey))) {
valuesMemory.set(resolvedKey, await defaults[defaultKey]?.value)
}
if (!isDefined(fetcherDefaults.get(resolvedKey))) {
fetcherDefaults.set(resolvedKey, await defaults[defaultKey]?.value)
}
}

if (!isDefined(cacheProvider.get(resolvedKey))) {
valuesMemory.set(resolvedKey, await defaults[defaultKey]?.value)
fetcherDefaults.set(resolvedKey, await defaults[defaultKey]?.value)
cacheProvider.set(resolvedKey, await defaults[defaultKey]?.value)
}
}
Expand Down
24 changes: 6 additions & 18 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,11 @@ export function FetchConfig(props: FetchContextType) {
parsedChunk = dataChunk
}

if (!isDefined(valuesMemory.get(resolvedKey))) {
valuesMemory.set(resolvedKey, parsedChunk)
}
if (!isDefined(fetcherDefaults.get(resolvedKey))) {
fetcherDefaults.set(resolvedKey, parsedChunk)
}
valuesMemory.set(resolvedKey, parsedChunk)

if (!isDefined(cacheProvider.get(resolvedKey))) {
cacheProvider.set(resolvedKey, parsedChunk)
}
fetcherDefaults.set(resolvedKey, parsedChunk)

cacheProvider.set(resolvedKey, parsedChunk)
}

for (let defaultKey in defaults) {
Expand All @@ -96,15 +91,8 @@ export function FetchConfig(props: FetchContextType) {
})

if (isDefined(id)) {
if (!isDefined(valuesMemory.get(resolvedKey))) {
valuesMemory.set(resolvedKey, defaults[defaultKey]?.value)
}
if (!isDefined(fetcherDefaults.get(resolvedKey))) {
fetcherDefaults.set(resolvedKey, defaults[defaultKey]?.value)
}
}

if (!isDefined(cacheProvider.get(resolvedKey))) {
valuesMemory.set(resolvedKey, defaults[defaultKey]?.value)
fetcherDefaults.set(resolvedKey, defaults[defaultKey]?.value)
cacheProvider.set(resolvedKey, defaults[defaultKey]?.value)
}
}
Expand Down

0 comments on commit a63c74b

Please sign in to comment.