Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mobile): split store into entity and model #15666

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shenlong-tanwen
Copy link
Member

@shenlong-tanwen shenlong-tanwen commented Jan 25, 2025

Changes made

  • Refactored the App Store to use the repository pattern
  • Split the Entity into two - Entity and Model / DTO to make it easier to replace the entity alone in the future
  • Moved the store repository to the domain folder. The idea is to have all business logic and handling inside the domain layer and expose the services to the presentation layer
lib/
├─ domain/
├─ presentation/
├─ utils/
  • The old store values are migrated to the new entity during the migration.
  • A stub User entity and DTO to add and remove them to the new store. The old User entity and repository has to be migrated to use the new ones during the user entity split

TODO

  • Domain test cases for the store


part 'user.entity.g.dart';

@Collection(inheritance: false, accessor: 'usr')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the accessor and should we spell out the whole word as user?

// Isar do not support nested transactions. This is a workaround to prevent us from making nested transactions
// Reuse the current transaction if it is already active, else start a new transaction
@override
Future<T> nestTxn<T>(Future<T> Function() callback) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need nestTxn? I haven't seen this mechanism used in the backend or current mobile codebase?

}

static Store? _instance;
static Store get I {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Store.I.xxx is singleton I assume? What is the notion of I borrow from? is it from .NET world? :D

Copy link
Contributor

@alextran1502 alextran1502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is not completed yet, correct? I tried to run it on the phone and still running into many errors

lib/pages/share_intent/share_intent.page.dart:22:37: Error: Undefined name 'StoreKey'.
        db_store.Store.get(db_store.StoreKey.serverEndpoint);
                                    ^^^^^^^^
lib/pages/share_intent/share_intent.page.dart:22:18: Error: Undefined name 'Store'.
        db_store.Store.get(db_store.StoreKey.serverEndpoint);
                 ^^^^^
lib/repositories/album.repository.dart:50:38: Error: Member not found: 'Store.get'.
        (q) => q.isarIdEqualTo(Store.get(StoreKey.currentUser).isarId),
                                     ^^^
lib/repositories/album.repository.dart:54:44: Error: Member not found: 'Store.get'.
        (q) => q.not().isarIdEqualTo(Store.get(StoreKey.currentUser).isarId),
        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants