mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-08-04 01:51:49 +00:00
Extract datasource instances from app.tsx
This commit is contained in:
@@ -81,7 +81,7 @@ To refactor `app.tsx` safely and maintain continuous code correctness, we will m
|
|||||||
|
|
||||||
#### Phase 1: Pure Component and Utility Extraction
|
#### Phase 1: Pure Component and Utility Extraction
|
||||||
* [x] **Step 1.1:** Create `src/components/error_display.tsx` and move `ErrorMessage` and `ErrorPopup` from `src/app.tsx`. Update imports in `src/app.tsx`.
|
* [x] **Step 1.1:** Create `src/components/error_display.tsx` and move `ErrorMessage` and `ErrorPopup` from `src/app.tsx`. Update imports in `src/app.tsx`.
|
||||||
* [ ] **Step 1.2:** Create `src/datasource/instances.ts` and move data source class instantiations. Update references in `src/app.tsx`. Refactor `EmbeddedDataSource` to clean up its message event listener when the loading promise resolves or rejects (or track listener state) to prevent duplicate event listener leaks on multiple page mounts.
|
* [x] **Step 1.2:** Create `src/datasource/instances.ts` and move data source class instantiations. Update references in `src/app.tsx`. Refactor `EmbeddedDataSource` to clean up its message event listener when the loading promise resolves or rejects (or track listener state) to prevent duplicate event listener leaks on multiple page mounts.
|
||||||
* [ ] **Step 1.3:** Create `src/util/url_args.ts` (the parsing utility) and `src/util/url_args.spec.ts` (its Jest unit test suite) together. Extract URL query parameter parsing functions and types from `src/app.tsx`, write comprehensive tests, update imports in `src/app.tsx`, and run `npm test` to verify.
|
* [ ] **Step 1.3:** Create `src/util/url_args.ts` (the parsing utility) and `src/util/url_args.spec.ts` (its Jest unit test suite) together. Extract URL query parameter parsing functions and types from `src/app.tsx`, write comprehensive tests, update imports in `src/app.tsx`, and run `npm test` to verify.
|
||||||
* [ ] **Step 1.4:** Modify `src/menu/top_bar.tsx` to make chart-specific props and event handlers optional (e.g. `data`, `allowAllRelativesChart`, `allowPrintAndDownload`, `eventHandlers`, etc.), preparing the component for rendering on the landing screen without dummy properties.
|
* [ ] **Step 1.4:** Modify `src/menu/top_bar.tsx` to make chart-specific props and event handlers optional (e.g. `data`, `allowAllRelativesChart`, `allowPrintAndDownload`, `eventHandlers`, etc.), preparing the component for rendering on the landing screen without dummy properties.
|
||||||
|
|
||||||
|
|||||||
16
src/app.tsx
16
src/app.tsx
@@ -15,10 +15,9 @@ import {
|
|||||||
} from './chart';
|
} from './chart';
|
||||||
import {ErrorMessage, ErrorPopup} from './components/error_display';
|
import {ErrorMessage, ErrorPopup} from './components/error_display';
|
||||||
import {DataSourceEnum, SourceSelection} from './datasource/data_source';
|
import {DataSourceEnum, SourceSelection} from './datasource/data_source';
|
||||||
import {EmbeddedDataSource, EmbeddedSourceSpec} from './datasource/embedded';
|
import {EmbeddedSourceSpec} from './datasource/embedded';
|
||||||
import {
|
import {
|
||||||
GoogleDriveAuthError,
|
GoogleDriveAuthError,
|
||||||
GoogleDriveDataSource,
|
|
||||||
GoogleDriveSourceSpec,
|
GoogleDriveSourceSpec,
|
||||||
} from './datasource/google_drive';
|
} from './datasource/google_drive';
|
||||||
import {
|
import {
|
||||||
@@ -27,10 +26,14 @@ import {
|
|||||||
isGoogleDriveConfigured,
|
isGoogleDriveConfigured,
|
||||||
} from './datasource/google_drive_service';
|
} from './datasource/google_drive_service';
|
||||||
import {
|
import {
|
||||||
GedcomUrlDataSource,
|
embeddedDataSource,
|
||||||
|
gedcomUrlDataSource,
|
||||||
|
googleDriveDataSource,
|
||||||
|
uploadedDataSource,
|
||||||
|
} from './datasource/instances';
|
||||||
|
import {
|
||||||
getSelection,
|
getSelection,
|
||||||
revokeObjectUrls,
|
revokeObjectUrls,
|
||||||
UploadedDataSource,
|
|
||||||
UploadSourceSpec,
|
UploadSourceSpec,
|
||||||
UrlSourceSpec,
|
UrlSourceSpec,
|
||||||
} from './datasource/load_data';
|
} from './datasource/load_data';
|
||||||
@@ -208,11 +211,6 @@ function getArguments(location: H.Location): Arguments {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadedDataSource = new UploadedDataSource();
|
|
||||||
const gedcomUrlDataSource = new GedcomUrlDataSource();
|
|
||||||
const embeddedDataSource = new EmbeddedDataSource();
|
|
||||||
const googleDriveDataSource = new GoogleDriveDataSource();
|
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
/** State of the application. */
|
/** State of the application. */
|
||||||
const [state, setState] = useState<AppState>(AppState.INITIAL);
|
const [state, setState] = useState<AppState>(AppState.INITIAL);
|
||||||
|
|||||||
8
src/datasource/instances.ts
Normal file
8
src/datasource/instances.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import {EmbeddedDataSource} from './embedded';
|
||||||
|
import {GoogleDriveDataSource} from './google_drive';
|
||||||
|
import {GedcomUrlDataSource, UploadedDataSource} from './load_data';
|
||||||
|
|
||||||
|
export const uploadedDataSource = new UploadedDataSource();
|
||||||
|
export const gedcomUrlDataSource = new GedcomUrlDataSource();
|
||||||
|
export const embeddedDataSource = new EmbeddedDataSource();
|
||||||
|
export const googleDriveDataSource = new GoogleDriveDataSource();
|
||||||
Reference in New Issue
Block a user