Skip to content

Commit

Permalink
Merge pull request #28 from czfadmin/pref_use_mobx
Browse files Browse the repository at this point in the history
Pref: 使用 mobx + mst 重构配置以及书签相关代码
  • Loading branch information
czfadmin authored Mar 15, 2024
2 parents eb89071 + f5a4e12 commit 8b2cdb7
Show file tree
Hide file tree
Showing 30 changed files with 1,505 additions and 955 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 0.0.28

### Patch Changes

- 954e0ef: 增加mst, 使用mobx改造BookmarkController
- 2db8f88: feat:使用mst改造插件配置
- feat:优化BookmarkController代码,同时修复上次提交产生的BUG

## 0.0.27

### Patch Changes
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bookmark-manager",
"displayName": "Bookmark Manager (BM)",
"description": "Simple and easy to use bookmark manager",
"version": "0.0.27",
"version": "0.0.28",
"engines": {
"vscode": "^1.82.0"
},
Expand Down Expand Up @@ -492,7 +492,7 @@
},
{
"command": "bookmark-manager.clearAllBookmarksInCurrentFile",
"when": "view == bookmark-manager && viewItem === file",
"when": "view == bookmark-manager && (viewItem === file || viewItem === workspace)",
"group": "inline@2"
},
{
Expand Down Expand Up @@ -614,6 +614,8 @@
"@vscode/l10n": "^0.0.16",
"@vscode/vsce": "^2.23.0",
"lodash": "^4.17.21",
"mobx": "^6.12.0",
"mobx-state-tree": "^5.4.1",
"uuid": "^9.0.1"
},
"lint-staged": {
Expand Down
47 changes: 29 additions & 18 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ import {registerTelemetryLogger} from './utils';
import logger from './utils/logger';

import {
ServiceManager,
initServiceManager,
postInitController,
} from './services/ServiceManager';

let controllerManager: any = {};
let controllerManager: {
bookmarks?: BookmarksController;
universal?: UniversalBookmarkController;
} = {};

/**
* 注册所有的视图
Expand Down Expand Up @@ -55,13 +59,17 @@ function updateEverything() {
updateTextEditorSelectionListener();
}

function initialController(context: ExtensionContext) {
controllerManager['bookmarks'] && controllerManager['bookmarks'].dispose();
controllerManager['universal'] && controllerManager['universal'].dispose();
const bookmarksController = new BookmarksController(context);
const universalController = new UniversalBookmarkController(context);
controllerManager['bookmarks'] = bookmarksController;
controllerManager['universal'] = universalController;
function initialController(
context: ExtensionContext,
serviceManager: ServiceManager,
) {
const bookmarksController = new BookmarksController(context, serviceManager);
const universalController = new UniversalBookmarkController(
context,
serviceManager,
);
controllerManager.bookmarks = bookmarksController;
controllerManager.universal = universalController;
}

export default async function bootstrap(context: ExtensionContext) {
Expand All @@ -71,20 +79,23 @@ export default async function bootstrap(context: ExtensionContext) {
context.subscriptions.push(registerTelemetryLogger());

logger.log(`${EXTENSION_ID} is now active!`);

await initServiceManager(context, updateEverything);

initialController(context);
postInitController();
registerAllTreeView(context);
registerAllCommands();
updateEverything();
try {
const sm = await initServiceManager(context, updateEverything);
initialController(context, sm);
postInitController();
registerAllTreeView(context);
registerAllCommands();
updateEverything();
} catch (error) {
console.error(error);
logger.error(error);
}
}

export function resolveBookmarkController(): BookmarksController {
return controllerManager['bookmarks'];
return controllerManager.bookmarks!;
}

export function resolveUniversalController(): UniversalBookmarkController {
return controllerManager['universal'];
return controllerManager.universal!;
}
Loading

0 comments on commit 8b2cdb7

Please sign in to comment.