@magnetarjs/core
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -425,2 +425,9 @@ 'use strict'; | ||
if (actionName === 'fetch') { | ||
if (payload && payload.ifUnfetched === true) { | ||
const localStoreName = moduleConfig.localStoreName || globalConfig.localStoreName; | ||
// the local store successfully returned a fetch response based on already fetched data | ||
if (storeName === localStoreName && isFetchResponse(resultFromPlugin)) { | ||
stopExecutionAfterAction(true); | ||
} | ||
} | ||
if (isDoOnFetch(resultFromPlugin)) { | ||
@@ -427,0 +434,0 @@ doOnFetchFns.push(resultFromPlugin); |
@@ -421,2 +421,9 @@ import { merge, mergeAndConcat } from 'merge-anything'; | ||
if (actionName === 'fetch') { | ||
if (payload && payload.ifUnfetched === true) { | ||
const localStoreName = moduleConfig.localStoreName || globalConfig.localStoreName; | ||
// the local store successfully returned a fetch response based on already fetched data | ||
if (storeName === localStoreName && isFetchResponse(resultFromPlugin)) { | ||
stopExecutionAfterAction(true); | ||
} | ||
} | ||
if (isDoOnFetch(resultFromPlugin)) { | ||
@@ -423,0 +430,0 @@ doOnFetchFns.push(resultFromPlugin); |
{ | ||
"name": "@magnetarjs/core", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"sideEffects": false, | ||
@@ -26,3 +26,3 @@ "description": "Magnetar core library.", | ||
"devDependencies": { | ||
"@magnetarjs/test-utils": "^0.0.11", | ||
"@magnetarjs/test-utils": "^0.0.12", | ||
"ava": "^3.15.0" | ||
@@ -71,3 +71,3 @@ }, | ||
}, | ||
"gitHead": "ad27bdb9bb5fba289ffdb3abe4c94e1b94072160" | ||
"gitHead": "431709c8bde8a6a626b4366750097be8ca232472" | ||
} |
@@ -173,2 +173,9 @@ /* eslint-disable no-inner-declarations */ | ||
if (actionName === 'fetch') { | ||
if (payload && payload.ifUnfetched === true) { | ||
const localStoreName = moduleConfig.localStoreName || globalConfig.localStoreName | ||
// the local store successfully returned a fetch response based on already fetched data | ||
if (storeName === localStoreName && isFetchResponse(resultFromPlugin)) { | ||
stopExecutionAfterAction(true) | ||
} | ||
} | ||
if (isDoOnFetch(resultFromPlugin)) { | ||
@@ -175,0 +182,0 @@ doOnFetchFns.push(resultFromPlugin) |
@@ -43,3 +43,4 @@ import { | ||
export function createMagnetarInstance( | ||
magnetarGlobalConfig: Partial<GlobalConfig> = {} | ||
magnetarGlobalConfig: Partial<GlobalConfig> = {}, | ||
startEmpty = false | ||
): { | ||
@@ -62,15 +63,19 @@ pokedexModule: CollectionInstance<PokedexModuleData> | ||
}) | ||
const pokedexModule = magnetar.collection<PokedexModuleData>('pokedex', { | ||
configPerStore: { | ||
local: { initialData: getInitialDataCollection() }, // path for the plugin | ||
remote: {}, // path for the plugin | ||
}, | ||
}) | ||
const trainerModule = magnetar.doc<TrainerModuleData>('app-data/trainer', { | ||
configPerStore: { | ||
local: { initialData: getInitialDataDocument() }, // path for the plugin | ||
remote: {}, // path for the plugin | ||
}, | ||
}) | ||
const pokedexModule = startEmpty | ||
? magnetar.collection<PokedexModuleData>('pokedex') | ||
: magnetar.collection<PokedexModuleData>('pokedex', { | ||
configPerStore: { | ||
local: { initialData: getInitialDataCollection() }, // path for the plugin | ||
remote: {}, // path for the plugin | ||
}, | ||
}) | ||
const trainerModule = startEmpty | ||
? magnetar.doc<TrainerModuleData>('app-data/trainer') | ||
: magnetar.doc<TrainerModuleData>('app-data/trainer', { | ||
configPerStore: { | ||
local: { initialData: getInitialDataDocument() }, // path for the plugin | ||
remote: {}, // path for the plugin | ||
}, | ||
}) | ||
return { pokedexModule, trainerModule, magnetar } | ||
} |
@@ -22,7 +22,6 @@ import test from 'ava' | ||
test('read: fetch (document)', async (t) => { | ||
test('read: fetch (document) - prevent multiple fetch requests at the same time', async (t) => { | ||
// get resolves once all stores have given a response with data | ||
const storeNames: string[] = [] | ||
const { magnetar } = createMagnetarInstance() | ||
const trainerModule = magnetar.doc('app-data/trainer', { | ||
const { trainerModule } = createMagnetarInstance({ | ||
on: { | ||
@@ -57,25 +56,43 @@ success: ({ storeName }: any) => { | ||
// test('fetch (collection) where-filter: ==', async (t) => { | ||
// const { pokedexModule, magnetar } = createMagnetarInstance() | ||
test('read: fetch (document) - ifUnfetched', async (t) => { | ||
// get resolves once all stores have given a response with data | ||
const storeNames: string[] = [] | ||
const startEmpty = true | ||
const { trainerModule } = createMagnetarInstance( | ||
{ | ||
on: { | ||
success: ({ storeName }: any) => { | ||
storeNames.push(storeName) | ||
}, | ||
}, | ||
}, | ||
startEmpty | ||
) | ||
try { | ||
// fetch twice at the same time | ||
await Promise.all([ | ||
trainerModule.fetch({ ifUnfetched: true }), | ||
trainerModule.fetch({ ifUnfetched: true }), | ||
]) | ||
} catch (error) { | ||
t.fail(error) | ||
} | ||
// const pokedexModuleWithQuery = pokedexModule.where('name', '==', 'Flareon') | ||
// try { | ||
// const queryModuleRef = await pokedexModuleWithQuery.fetch() | ||
// t.deepEqual([...queryModuleRef.data.values()], [pokedex(136)]) | ||
// } catch (error) { | ||
// t.fail(error) | ||
// } | ||
// // try take the query again and see if it's the same result | ||
// const queryModuleRef = pokedexModule.where('name', '==', 'Flareon') | ||
// t.deepEqual([...queryModuleRef.data.values()], [pokedex(136)]) | ||
// // try take the pokedexModuleWithQuery and see if it's the same result | ||
// t.deepEqual([...pokedexModuleWithQuery.data.values()], [pokedex(136)]) | ||
// // check the invididual doc refs from the pokedexModuleWithQuery | ||
// t.deepEqual(pokedexModuleWithQuery.doc('136').data, pokedex(136)) | ||
// // check the invididual doc refs from pokedexModule | ||
// t.deepEqual(pokedexModule.doc('136').data, pokedex(136)) | ||
// // check the invididual doc refs from base | ||
// t.deepEqual(magnetar.doc('pokedex/136').data, pokedex(136)) | ||
// // see if the main module has also received this data | ||
// t.deepEqual([...pokedexModule.data.values()], [pokedex(1), pokedex(136)]) | ||
// }) | ||
// make sure the remote store was only triggered once | ||
t.is(storeNames.filter((n) => n === 'remote').length, 1) | ||
try { | ||
// fetch twice again the same time | ||
await Promise.all([ | ||
trainerModule.fetch({ ifUnfetched: true }), | ||
trainerModule.fetch({ ifUnfetched: true }), | ||
]) | ||
} catch (error) { | ||
t.fail(error) | ||
} | ||
// make sure the remote store was not triggered again | ||
t.is(storeNames.filter((n) => n === 'remote').length, 1) | ||
t.deepEqual(trainerModule.data, { name: 'Luca', age: 10, dream: 'job' }) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
262027
5904