Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3354519
D11280.id38266.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11280.id38266.diff
View Options
diff --git a/lib/reducers/db-ops-reducer.js b/lib/reducers/db-ops-reducer.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/db-ops-reducer.js
@@ -0,0 +1,19 @@
+// @flow
+
+import { opsProcessingFinishedActionType } from '../actions/db-ops-actions.js';
+import type { DBOpsStore } from '../types/db-ops-types.js';
+import type { BaseAction } from '../types/redux-types.js';
+
+function reduceDBOpsStore(store: DBOpsStore, action: BaseAction): DBOpsStore {
+ if (action.type === opsProcessingFinishedActionType) {
+ const ids = new Set(action.payload.actionIDs);
+ return {
+ ...store,
+ queuedOps: store.queuedOps.filter(ops => !ids.has(ops.actionID)),
+ noOpsActions: store.noOpsActions.filter(id => !ids.has(id)),
+ };
+ }
+ return store;
+}
+
+export { reduceDBOpsStore };
diff --git a/lib/reducers/db-ops-reducer.test.js b/lib/reducers/db-ops-reducer.test.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/db-ops-reducer.test.js
@@ -0,0 +1,73 @@
+// @flow
+
+import { reduceDBOpsStore } from './db-ops-reducer.js';
+import { opsProcessingFinishedActionType } from '../actions/db-ops-actions.js';
+import type { DBOpsStore } from '../types/db-ops-types.js';
+
+const emptyOps = {
+ draftStoreOperations: [],
+ threadStoreOperations: [],
+ messageStoreOperations: [],
+ reportStoreOperations: [],
+ userStoreOperations: [],
+ keyserverStoreOperations: [],
+ communityStoreOperations: [],
+};
+
+describe('DB ops reducer', () => {
+ const store: DBOpsStore = {
+ queuedOps: [
+ { ops: emptyOps, actionID: '5' },
+ { ops: emptyOps, actionID: '6' },
+ { ops: emptyOps, actionID: '7' },
+ ],
+ noOpsActions: ['3', '9', '8'],
+ };
+
+ it('should filter ops', () => {
+ const newState = reduceDBOpsStore(store, {
+ type: opsProcessingFinishedActionType,
+ payload: { actionIDs: ['6'] },
+ });
+ expect(newState.queuedOps.length).toEqual(2);
+ expect(newState.queuedOps[0].actionID).toEqual('5');
+ expect(newState.queuedOps[1].actionID).toEqual('7');
+ });
+
+ it('should filter actions without ops', () => {
+ const newState = reduceDBOpsStore(store, {
+ type: opsProcessingFinishedActionType,
+ payload: { actionIDs: ['3', '9'] },
+ });
+ expect(newState.noOpsActions.length).toEqual(1);
+ expect(newState.noOpsActions[0]).toEqual('8');
+ });
+
+ it('should filter both queues', () => {
+ const newState = reduceDBOpsStore(store, {
+ type: opsProcessingFinishedActionType,
+ payload: { actionIDs: ['6', '3'] },
+ });
+ expect(newState.noOpsActions.length).toEqual(2);
+ expect(newState.queuedOps.length).toEqual(2);
+ });
+
+ it("shouldn't filter ops when ids aren't present", () => {
+ const newState = reduceDBOpsStore(store, {
+ type: opsProcessingFinishedActionType,
+ payload: { actionIDs: ['10'] },
+ });
+ expect(newState.noOpsActions.length).toEqual(3);
+ expect(newState.queuedOps.length).toEqual(3);
+ });
+
+ it("shouldn't change queue order", () => {
+ const newState = reduceDBOpsStore(store, {
+ type: opsProcessingFinishedActionType,
+ payload: { actionIDs: ['5'] },
+ });
+ expect(newState.queuedOps.length).toEqual(2);
+ expect(newState.queuedOps[0].actionID).toEqual('6');
+ expect(newState.queuedOps[1].actionID).toEqual('7');
+ });
+});
diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js
--- a/lib/reducers/master-reducer.js
+++ b/lib/reducers/master-reducer.js
@@ -4,6 +4,7 @@
import { reduceCommunityStore } from './community-reducer.js';
import reduceCustomerServer from './custom-server-reducer.js';
import reduceDataLoaded from './data-loaded-reducer.js';
+import { reduceDBOpsStore } from './db-ops-reducer.js';
import { reduceDraftStore } from './draft-reducer.js';
import reduceEnabledApps from './enabled-apps-reducer.js';
import { reduceEntryInfos } from './entry-reducer.js';
@@ -206,6 +207,7 @@
globalThemeInfo: reduceGlobalThemeInfo(state.globalThemeInfo, action),
customServer: reduceCustomerServer(state.customServer, action),
communityStore,
+ dbOpsStore: reduceDBOpsStore(state.dbOpsStore, action),
},
storeOperations: {
draftStoreOperations,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 12:55 PM (21 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2575773
Default Alt Text
D11280.id38266.diff (4 KB)
Attached To
Mode
D11280: [lib] Add a reducer that handles successful ops processing
Attached
Detach File
Event Timeline
Log In to Comment