Skip to content

Commit

Permalink
⚡️ perf: 首次加载优化 #24
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Oct 3, 2024
1 parent 9aa1f08 commit 4a8de1c
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sy-bookmark-plus",
"version": "1.3.3",
"version": "1.4.0-dev1",
"type": "module",
"description": "A more powerful bookmark",
"repository": "",
Expand All @@ -24,7 +24,7 @@
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
"sass": "^1.72.0",
"siyuan": "0.9.9",
"siyuan": "1.0.3",
"solid-js": "^1.8.17",
"solid-styled-jsx": "^0.27.1",
"ts-node": "^10.9.2",
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sy-bookmark-plus",
"author": "frostime",
"url": "https://github.com/frostime/sy-bookmark-plus",
"version": "1.3.3",
"version": "1.4.0-dev1",
"minAppVersion": "3.0.12",
"backends": [
"all"
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author : frostime
* @Date : 2024-06-12 19:48:53
* @FilePath : /src/index.ts
* @LastEditTime : 2024-08-15 17:38:22
* @LastEditTime : 2024-10-03 14:55:24
* @Description :
*/
import {
Expand All @@ -26,11 +26,11 @@ import { setI18n } from "@/utils/i18n";

import "@/index.scss";
import { isMobile } from "./utils";
import { provide, purge } from "./libs/inject";

let model: BookmarkDataModel;

const initBookmark = async (ele: HTMLElement, plugin: PluginBookmarkPlus) => {
await model.updateAll();
ele.classList.add('fn__flex-column');

if (isMobile()) {
Expand All @@ -42,6 +42,7 @@ const initBookmark = async (ele: HTMLElement, plugin: PluginBookmarkPlus) => {
plugin: plugin,
model: model
}), ele);
await model.updateAll();
};

const destroyBookmark = () => {
Expand All @@ -65,7 +66,9 @@ export default class PluginBookmarkPlus extends Plugin {
}

async onload() {
setI18n(this.i18n);
setI18n(this.i18n as I18n);
provide<I18n>('i18n', this.i18n as I18n);
provide<PluginBookmarkPlus>('plugin', this);

let svgs = Object.values(Svg);
this.addIcons(svgs.join(''));
Expand Down Expand Up @@ -120,6 +123,7 @@ export default class PluginBookmarkPlus extends Plugin {
}

onunload(): void {
purge();
destroyBookmark();
bookmarkKeymap.custom = bookmarkKeymap.default;
// this.commands = this.commands.filter((command) => command.langKey !== 'F-Misc::Bookmark');
Expand Down
19 changes: 19 additions & 0 deletions src/libs/inject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Storage = {};

export const provide = <T>(key: string, value: T) => {
Storage[key] = value;
}

export const inject = <T>(key: string): T => {
return Storage[key];
}

export const purge = (key?: string) => {
if (key) {
delete Storage[key];
} else {
for (const key in Storage) {
delete Storage[key];
}
}
}
138 changes: 138 additions & 0 deletions src/types/i18n.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
interface I18n {
msg: {
ruleFailed: string;
ruleInvalid: string;
itemHasInGroup: string;
itemNotFoundInGroup: string;
groupNameEmpty: string;
};
itemErr: {
closed: string;
deleted: string;
};
setting: {
replaceDefault: {
title: string;
description: string;
};
viewMode: {
title: string;
description: string;
};
hideClosed: {
title: string;
description: string;
};
hideDeleted: {
title: string;
description: string;
};
grouplist: {
title: string;
description: string;
};
autoRefreshOnExpand: {
title: string;
description: string;
};
ariaLabel: {
title: string;
description: string;
};
};
viewMode: {
bookmark: string;
card: string;
};
bookmark: {
new: string;
delete: {
title: string;
desc: string;
};
cache: string;
logo: {
name: string;
setting: string;
add: string;
refresh: string;
expand: string;
collapse: string;
min: string;
};
};
group: {
msgexist: string;
msg404: string;
refresh: string;
copyref: string;
copylink: string;
msgcopy: string;
docflow: string;
rename: string;
edit: string;
delete: string;
move: string;
top: string;
up: string;
down: string;
bottom: string;
fromclipboard: string;
msgparse: string;
currentdoc: string;
msgdelconfirm: string[];
};
item: {
copyref: string;
copylink: string;
msgcopy: string;
style: string;
transfer: string;
move: string;
top: string;
bottom: string;
del: string;
checkerritem: string;
copyitem: string;
};
newgroup: {
name: string[];
type: string[];
rtype: string[];
rinput: string;
desc: {
sql: string;
backlinks: string;
attr: string;
};
choosetemplate: string;
postprocess: {
ariaLabel: string;
name: string;
omit: string;
fb2p: string;
b2doc: string;
};
};
bookmarktype: {
normal: string;
dynamic: string;
composed: string;
};
ruletype: {
sql: string;
backlinks: string;
attr: string;
};
template: {
sql: {
random: string;
updated: string;
thisday: string;
todo: string;
};
attr: {
dailynote: string;
};
};
}
7 changes: 3 additions & 4 deletions src/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* @Author : frostime
* @Date : 2024-07-07 18:57:06
* @FilePath : /src/utils/i18n.ts
* @LastEditTime : 2024-07-07 21:24:01
* @LastEditTime : 2024-09-28 22:07:01
* @Description :
*/
import type I18n from '@/../dev/i18n/zh_CN.json';

export let i18n: typeof I18n = {} as any;
export let i18n: I18n = {} as any;

export const setI18n = (_i18n_: any) => {
export const setI18n = (_i18n_: I18n) => {
i18n = new Proxy(_i18n_, {
set: (..._) => {
console.warn("Attempt to modify read-only i18n object");
Expand Down

0 comments on commit 4a8de1c

Please sign in to comment.