mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
upgrade to cordis v3 (#733)
Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
1 parent
498cd57016
commit
a56b1650be
33 files changed
+301
-262
No files matched your search
@@ -138,7 +138,7 @@ export async function apply(ctx: Context) {
|
||||
ctx.on('app/started', buildUI);
|
||||
const debouncedBuildUI = debounce(buildUI, 2000, { trailing: true });
|
||||
const triggerHotUpdate = (path?: string) => {
|
||||
if (path && !path.includes('/ui-default/') && !path.includes('/public/')) return;
|
||||
if (path && !path.includes('/ui-default/') && !path.includes('/public/') && !path.includes('/frontend/')) return;
|
||||
debouncedBuildUI();
|
||||
};
|
||||
ctx.on('system/setting', () => triggerHotUpdate());
|
||||
|
||||
@@ -7,7 +7,7 @@ import type * as monaco from 'monaco-editor';
|
||||
import React from 'react';
|
||||
import { useDispatch, useSelector, useStore } from 'react-redux';
|
||||
import Dom from 'vj/components/react/DomComponent';
|
||||
import { Context, ctx, Service } from 'vj/context';
|
||||
import { ctx, Service } from 'vj/context';
|
||||
import ScratchpadEditor from './ScratchpadEditorContainer';
|
||||
import ScratchpadPretest from './ScratchpadPretestContainer';
|
||||
import ScratchpadRecords from './ScratchpadRecordsContainer';
|
||||
@@ -54,7 +54,6 @@ class ScratchpadService extends Service {
|
||||
rerenderCallback?.();
|
||||
}
|
||||
}
|
||||
Context.service('scratchpad', ScratchpadService);
|
||||
declare module '../../context' {
|
||||
interface Context {
|
||||
scratchpad: ScratchpadService;
|
||||
@@ -63,6 +62,7 @@ declare module '../../context' {
|
||||
|
||||
export default function ScratchpadContainer() {
|
||||
const store = useStore();
|
||||
ctx.provide('scratchpad');
|
||||
ctx.scratchpad ||= new ScratchpadService(store);
|
||||
const [, updateState] = React.useState<any>();
|
||||
const forceUpdate = React.useCallback(() => updateState({}), []);
|
||||
|
||||
@@ -19,8 +19,8 @@ streamsaver.mitm = `${window.isSecureContext ? '' : 'https://hydro.ac'}/streamsa
|
||||
|
||||
const waitForWritableStream = window.WritableStream
|
||||
? Promise.resolve()
|
||||
: import('web-streams-polyfill/dist/ponyfill.es6').then(({ WritableStream }) => {
|
||||
window.WritableStream = WritableStream;
|
||||
: import('web-streams-polyfill').then(({ WritableStream }) => {
|
||||
window.WritableStream = WritableStream as any;
|
||||
streamsaver.WritableStream = window.WritableStream;
|
||||
});
|
||||
|
||||
|
||||
@@ -1,47 +1,38 @@
|
||||
import * as cordis from 'cordis';
|
||||
import type { EventMap } from './api';
|
||||
|
||||
export interface Events<C extends Context = Context> extends cordis.Events<C>, EventMap {
|
||||
}
|
||||
export interface Events<C extends Context = Context> extends cordis.Events<C>, EventMap { }
|
||||
|
||||
export type { Disposable, ScopeStatus, Plugin } from 'cordis';
|
||||
|
||||
export interface Context {
|
||||
[Context.events]: Events<Context>;
|
||||
setTimeout: typeof setTimeout;
|
||||
setInterval: typeof setInterval;
|
||||
api: ApiMixin;
|
||||
[Context.events]: Events<this>;
|
||||
broadcast: Context['emit'];
|
||||
}
|
||||
|
||||
export class Context extends cordis.Context {
|
||||
static readonly session = Symbol('session');
|
||||
/** @deprecated use `ctx.root` instead */
|
||||
get app() {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
/** @deprecated use `root.config` instead */
|
||||
get options() {
|
||||
return this.root.config;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Context {
|
||||
export interface Config extends cordis.Context.Config { }
|
||||
export type Associate<P extends string, C extends Context = Context> = cordis.Context.Associate<P, C>;
|
||||
}
|
||||
|
||||
export type MainScope = cordis.MainScope<Context>;
|
||||
export type EffectScope = cordis.EffectScope<Context>;
|
||||
export type ForkScope = cordis.ForkScope<Context>;
|
||||
export type Plugin = cordis.Plugin<Context>;
|
||||
export const Service = cordis.Service<Context>;
|
||||
export namespace Plugin {
|
||||
export type Function<T = any> = cordis.Plugin.Function<T, Context>;
|
||||
export type Constructor<T = any> = cordis.Plugin.Constructor<T, Context>;
|
||||
export type Object<S = any, T = any> = cordis.Plugin.Object<S, T, Context>;
|
||||
}
|
||||
|
||||
const T = <F extends (...args: any[]) => any>(origFunc: F, disposeFunc?) =>
|
||||
function method(this: cordis.Service, ...args: Parameters<F>) {
|
||||
const res = origFunc(...args);
|
||||
this.caller?.on('dispose', () => (disposeFunc ? disposeFunc(res) : res()));
|
||||
};
|
||||
export class ApiMixin extends Service {
|
||||
static readonly methods = ['setInterval', 'setTimeout'];
|
||||
setInterval = T(setInterval, clearInterval);
|
||||
setTimeout = T(setTimeout, clearTimeout);
|
||||
constructor(ctx) {
|
||||
super(ctx, 'api', true);
|
||||
export abstract class Service<T = any, C extends Context = Context> extends cordis.Service<T, C> {
|
||||
[cordis.Service.setup]() {
|
||||
this.ctx = new Context() as C;
|
||||
}
|
||||
}
|
||||
Context.service('api', ApiMixin);
|
||||
export const ctx = new Context();
|
||||
@@ -14,15 +14,15 @@
|
||||
"cli": false
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blueprintjs/core": "^5.9.1",
|
||||
"@fontsource/dm-mono": "^5.0.18",
|
||||
"@fontsource/fira-code": "^5.0.16",
|
||||
"@fontsource/inconsolata": "^5.0.16",
|
||||
"@fontsource/jetbrains-mono": "^5.0.18",
|
||||
"@fontsource/pt-mono": "^5.0.8",
|
||||
"@fontsource/roboto-mono": "^5.0.16",
|
||||
"@fontsource/source-code-pro": "^5.0.16",
|
||||
"@fontsource/ubuntu-mono": "^5.0.18",
|
||||
"@blueprintjs/core": "^5.10.0",
|
||||
"@fontsource/dm-mono": "^5.0.19",
|
||||
"@fontsource/fira-code": "^5.0.17",
|
||||
"@fontsource/inconsolata": "^5.0.17",
|
||||
"@fontsource/jetbrains-mono": "^5.0.19",
|
||||
"@fontsource/pt-mono": "^5.0.12",
|
||||
"@fontsource/roboto-mono": "^5.0.17",
|
||||
"@fontsource/source-code-pro": "^5.0.17",
|
||||
"@fontsource/ubuntu-mono": "^5.0.19",
|
||||
"@hydrooj/utils": "workspace:*",
|
||||
"@simplewebauthn/browser": "7.4.0",
|
||||
"@svgr/webpack": "^8.1.0",
|
||||
@@ -34,21 +34,21 @@
|
||||
"@types/nunjucks": "^3.2.6",
|
||||
"@types/pickadate": "^3.5.35",
|
||||
"@types/qrcode": "^1.5.5",
|
||||
"@types/react": "^18.2.57",
|
||||
"@types/react": "^18.2.63",
|
||||
"@types/react-dom": "^18.2.19",
|
||||
"@types/redux-logger": "^3.0.13",
|
||||
"@types/webpack-env": "^1.18.4",
|
||||
"@vscode/codicons": "^0.0.35",
|
||||
"ajv": "^8.12.0",
|
||||
"allotment": "^1.20.0",
|
||||
"autoprefixer": "^10.4.17",
|
||||
"browser-update": "^3.3.44",
|
||||
"autoprefixer": "^10.4.18",
|
||||
"browser-update": "^3.3.51",
|
||||
"chalk": "^5.3.0",
|
||||
"classnames": "^2.5.1",
|
||||
"clean-webpack-plugin": "^4.0.0",
|
||||
"clipboard": "^2.0.11",
|
||||
"copy-webpack-plugin": "^12.0.2",
|
||||
"cordis": "2.8.8",
|
||||
"cordis": "3.13.3",
|
||||
"css-loader": "^6.10.0",
|
||||
"diff": "^5.2.0",
|
||||
"diff-dom": "^5.1.2",
|
||||
@@ -69,7 +69,7 @@
|
||||
"jquery.easing": "^1.4.1",
|
||||
"jquery.transit": "^0.9.12",
|
||||
"matchmedia-polyfill": "^0.3.2",
|
||||
"mini-css-extract-plugin": "^2.8.0",
|
||||
"mini-css-extract-plugin": "^2.8.1",
|
||||
"moment": "^2.30.1",
|
||||
"monaco-editor": "0.46.0",
|
||||
"monaco-editor-nls": "^3.1.0",
|
||||
@@ -107,7 +107,7 @@
|
||||
"slideout": "^1.0.1",
|
||||
"sticky-kit": "^1.1.3",
|
||||
"style-loader": "^3.3.4",
|
||||
"stylus": "^0.62.0",
|
||||
"stylus": "^0.63.0",
|
||||
"stylus-loader": "7.1.2",
|
||||
"tether": "1.4.7",
|
||||
"tether-drop": "^1.4.2",
|
||||
@@ -115,9 +115,9 @@
|
||||
"timeago-react": "^3.0.6",
|
||||
"timeago.js": "^4.0.2",
|
||||
"ts-loader": "^9.5.1",
|
||||
"vditor": "^3.9.9",
|
||||
"vditor": "^3.10.1",
|
||||
"vinyl-buffer": "^1.0.1",
|
||||
"web-streams-polyfill": "^3.3.3",
|
||||
"web-streams-polyfill": "^4.0.0",
|
||||
"webpack": "^5.90.3",
|
||||
"webpack-bundle-analyzer": "^4.10.1",
|
||||
"webpack-dev-server": "^5.0.2",
|
||||
@@ -143,6 +143,6 @@
|
||||
"nunjucks": "^3.2.4",
|
||||
"schemastery-jsonschema": "^1.1.0",
|
||||
"streamsaver": "^2.0.6",
|
||||
"xss": "^1.0.14"
|
||||
"xss": "^1.0.15"
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import React from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import VjNotification from 'vj/components/notification';
|
||||
import selectUser from 'vj/components/selectUser';
|
||||
import { Context, ctx, Service } from 'vj/context';
|
||||
import { ctx, Service } from 'vj/context';
|
||||
import { NamedPage } from 'vj/misc/Page';
|
||||
import { api, gql, loadReactRedux } from 'vj/utils';
|
||||
|
||||
@@ -12,7 +12,7 @@ class MessagePadService extends Service {
|
||||
super(ctx, 'messagepad', true);
|
||||
}
|
||||
}
|
||||
Context.service('messagepad', MessagePadService);
|
||||
|
||||
declare module '../context' {
|
||||
interface Context {
|
||||
messagepad: MessagePadService;
|
||||
@@ -43,6 +43,7 @@ const page = new NamedPage('home_messages', () => {
|
||||
|
||||
reduxStore = store;
|
||||
(window as any).store = reduxStore;
|
||||
ctx.provide('messagepad');
|
||||
ctx.messagepad = new MessagePadService(store, WebSocket);
|
||||
|
||||
const sock = new WebSocket(`${UiContext.ws_prefix}home/messages-conn`);
|
||||
|
||||
Reference in new issue
Block a user