@magnetarjs/core
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -363,2 +363,3 @@ 'use strict'; | ||
return function (payload, actionConfig = {}) { | ||
// first of all, check if the same fetch call was just made or not, if so return the same fetch promise early | ||
const fetchPromiseKey = JSON.stringify(payload); | ||
@@ -369,2 +370,3 @@ const foundFetchPromise = fetchPromises.get(fetchPromiseKey); | ||
return foundFetchPromise; | ||
// set up and/or reset te writeLock for write actions | ||
const writeLock = _docId ? writeLockMap.get(`${collectionPath}/${_docId}`) : writeLockMap.get(collectionPath); | ||
@@ -639,2 +641,6 @@ if (actionName !== 'fetch') { | ||
/** | ||
* Last incoming modified docs are cached here temporarily to prevent UI flashing because of the writeLock | ||
*/ | ||
const lastIncomingModifiedDocs = new Map(); | ||
/** | ||
* this is what must be executed by a plugin store that implemented "stream" functionality | ||
@@ -652,10 +658,24 @@ */ | ||
modified: (_payload, _meta) => __awaiter(this, void 0, void 0, function* () { | ||
// check if there's a WriteLock for the document: | ||
const _writeLock = writeLockMap.get(`${collectionPath}/${_meta.id}`); | ||
const identifier = `${collectionPath}/${_meta.id}`; | ||
// add to lastIncoming map | ||
lastIncomingModifiedDocs.set(identifier, [_payload, _meta]); | ||
// check if there's a WriteLock for the document | ||
const _writeLock = writeLockMap.get(identifier); | ||
if (_writeLock && isWhat.isPromise(_writeLock.promise)) { | ||
yield _writeLock.promise; | ||
} | ||
return executeOnFns(doOnStreamFns.modified, _payload, [_meta]); | ||
// grab from lastIncoming map | ||
const [__payload, __meta] = lastIncomingModifiedDocs.get(identifier); | ||
// delete from lastIncoming map | ||
lastIncomingModifiedDocs.delete(identifier); | ||
// executer other plugin `doOnStream` functions | ||
return executeOnFns(doOnStreamFns.modified, __payload, [__meta]); | ||
}), | ||
removed: (_payload, _meta) => __awaiter(this, void 0, void 0, function* () { | ||
const identifier = `${collectionPath}/${_meta.id}`; | ||
// check if there's a WriteLock for the document | ||
const _writeLock = writeLockMap.get(identifier); | ||
if (_writeLock && isWhat.isPromise(_writeLock.promise)) { | ||
yield _writeLock.promise; | ||
} | ||
return executeOnFns(doOnStreamFns.removed, _payload, [_meta]); | ||
@@ -662,0 +682,0 @@ }), |
@@ -359,2 +359,3 @@ import { merge, mergeAndConcat } from 'merge-anything'; | ||
return function (payload, actionConfig = {}) { | ||
// first of all, check if the same fetch call was just made or not, if so return the same fetch promise early | ||
const fetchPromiseKey = JSON.stringify(payload); | ||
@@ -365,2 +366,3 @@ const foundFetchPromise = fetchPromises.get(fetchPromiseKey); | ||
return foundFetchPromise; | ||
// set up and/or reset te writeLock for write actions | ||
const writeLock = _docId ? writeLockMap.get(`${collectionPath}/${_docId}`) : writeLockMap.get(collectionPath); | ||
@@ -635,2 +637,6 @@ if (actionName !== 'fetch') { | ||
/** | ||
* Last incoming modified docs are cached here temporarily to prevent UI flashing because of the writeLock | ||
*/ | ||
const lastIncomingModifiedDocs = new Map(); | ||
/** | ||
* this is what must be executed by a plugin store that implemented "stream" functionality | ||
@@ -648,10 +654,24 @@ */ | ||
modified: (_payload, _meta) => __awaiter(this, void 0, void 0, function* () { | ||
// check if there's a WriteLock for the document: | ||
const _writeLock = writeLockMap.get(`${collectionPath}/${_meta.id}`); | ||
const identifier = `${collectionPath}/${_meta.id}`; | ||
// add to lastIncoming map | ||
lastIncomingModifiedDocs.set(identifier, [_payload, _meta]); | ||
// check if there's a WriteLock for the document | ||
const _writeLock = writeLockMap.get(identifier); | ||
if (_writeLock && isPromise(_writeLock.promise)) { | ||
yield _writeLock.promise; | ||
} | ||
return executeOnFns(doOnStreamFns.modified, _payload, [_meta]); | ||
// grab from lastIncoming map | ||
const [__payload, __meta] = lastIncomingModifiedDocs.get(identifier); | ||
// delete from lastIncoming map | ||
lastIncomingModifiedDocs.delete(identifier); | ||
// executer other plugin `doOnStream` functions | ||
return executeOnFns(doOnStreamFns.modified, __payload, [__meta]); | ||
}), | ||
removed: (_payload, _meta) => __awaiter(this, void 0, void 0, function* () { | ||
const identifier = `${collectionPath}/${_meta.id}`; | ||
// check if there's a WriteLock for the document | ||
const _writeLock = writeLockMap.get(identifier); | ||
if (_writeLock && isPromise(_writeLock.promise)) { | ||
yield _writeLock.promise; | ||
} | ||
return executeOnFns(doOnStreamFns.removed, _payload, [_meta]); | ||
@@ -658,0 +678,0 @@ }), |
@@ -45,2 +45,6 @@ import { O } from 'ts-toolbelt'; | ||
getModuleData?: (pluginModuleSetupPayload: PluginModuleSetupPayload) => Record<string, any> | Map<string, Record<string, any>>; | ||
/** | ||
* This is an optional function that some "remote" Store Plugins can provide to sync any pending writes that might have stacked because of a `syncDebounceMs`. | ||
*/ | ||
syncPendingWrites?: () => Promise<void>; | ||
} | ||
@@ -47,0 +51,0 @@ /** |
{ | ||
"name": "@magnetarjs/core", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"sideEffects": false, | ||
@@ -69,3 +69,3 @@ "description": "Magnetar core library.", | ||
}, | ||
"gitHead": "af355f4565a623db246e927329af4f79dc27082d" | ||
"gitHead": "b83b88837ec3265481b2b6d3e623b4bba663a858" | ||
} |
@@ -57,2 +57,3 @@ /* eslint-disable no-inner-declarations */ | ||
return function (payload?: any, actionConfig: ActionConfig = {}): Promise<any> { | ||
// first of all, check if the same fetch call was just made or not, if so return the same fetch promise early | ||
const fetchPromiseKey = JSON.stringify(payload) | ||
@@ -63,2 +64,3 @@ const foundFetchPromise = fetchPromises.get(fetchPromiseKey) | ||
// set up and/or reset te writeLock for write actions | ||
const writeLock = _docId ? writeLockMap.get(`${collectionPath}/${_docId}`)! : writeLockMap.get(collectionPath)! | ||
@@ -65,0 +67,0 @@ if (actionName !== 'fetch') { |
@@ -75,2 +75,6 @@ import { O } from 'ts-toolbelt' | ||
/** | ||
* Last incoming modified docs are cached here temporarily to prevent UI flashing because of the writeLock | ||
*/ | ||
const lastIncomingModifiedDocs: Map<string, [any, any]> = new Map() | ||
/** | ||
* this is what must be executed by a plugin store that implemented "stream" functionality | ||
@@ -88,10 +92,29 @@ */ | ||
modified: async (_payload, _meta) => { | ||
// check if there's a WriteLock for the document: | ||
const _writeLock = writeLockMap.get(`${collectionPath}/${_meta.id}`) | ||
const identifier = `${collectionPath}/${_meta.id}` | ||
// add to lastIncoming map | ||
lastIncomingModifiedDocs.set(identifier, [_payload, _meta]) | ||
// check if there's a WriteLock for the document | ||
const _writeLock = writeLockMap.get(identifier) | ||
if (_writeLock && isPromise(_writeLock.promise)) { | ||
await _writeLock.promise | ||
} | ||
return executeOnFns(doOnStreamFns.modified, _payload, [_meta]) | ||
// grab from lastIncoming map | ||
const [__payload, __meta] = lastIncomingModifiedDocs.get(identifier) as [any, any] | ||
// delete from lastIncoming map | ||
lastIncomingModifiedDocs.delete(identifier) | ||
// executer other plugin `doOnStream` functions | ||
return executeOnFns(doOnStreamFns.modified, __payload, [__meta]) | ||
}, | ||
removed: async (_payload, _meta) => { | ||
const identifier = `${collectionPath}/${_meta.id}` | ||
// check if there's a WriteLock for the document | ||
const _writeLock = writeLockMap.get(identifier) | ||
if (_writeLock && isPromise(_writeLock.promise)) { | ||
await _writeLock.promise | ||
} | ||
return executeOnFns(doOnStreamFns.removed, _payload, [_meta]) | ||
@@ -98,0 +121,0 @@ }, |
@@ -55,2 +55,6 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
) => Record<string, any> | Map<string, Record<string, any>> | ||
/** | ||
* This is an optional function that some "remote" Store Plugins can provide to sync any pending writes that might have stacked because of a `syncDebounceMs`. | ||
*/ | ||
syncPendingWrites?: () => Promise<void> | ||
} | ||
@@ -57,0 +61,0 @@ |
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
293408
6725