HomePhabricator
Diffusion Comm 90567f87602c

[CommCoreModule] introduce BaseDataStore template class

Description

[CommCoreModule] introduce BaseDataStore template class

Summary:
Problems I want to solve:

  1. Code duplication - this part of code is duplicated at least 5 times (and will grow).
  1. Lack of separation - a lot of not related code like parsing is here, this can be grouped logically.

How it works:

  1. This template class provides two generic functions which will be reused (processStoreOperations, processStoreOperationsSync) - this solves problem 1.
  2. Has two pure virtual methods which need to be overridden (parseDBDataStore, createOperations), those methods are specialized for each data type (Messages, Threads, etc.) - this solves problem 2.

Why .h file?
When a template is used in C++, the compiler needs access to the entire template definition (not just a declaration) because it needs to generate the code for the specific instantiation at the compile time. (source).

Why not static methods when the class does not have a state?
I wanted to ensure that each child class (which will inherit from BaseDataStore) will override methods for parsing and creating ops. This can not be achieved easily with static methods - but I am open to modifying if someone has valid suggestions.

For more details check the next diff in the stack.

Depends on D8601

Test Plan: Build iOS and Android (rest is tested in detailed implementation in next diffs).

Reviewers: michal, jon, atul, tomek, marcin

Reviewed By: michal, jon, atul, tomek

Subscribers: marcin, ashoat

Differential Revision: https://phab.comm.dev/D8603

Details

Provenance
kamilAuthored on Jul 24 2023, 2:43 AM
Reviewer
michal
Differential Revision
D8603: [CommCoreModule] introduce BaseDataStore template class
Parents
rCOMMc1edc0cb9b40: [CommCoreModule] Move `runSyncOrThrowJSError` to a separate file
Branches
Unknown
Tags
Unknown