mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 04:46:02 +00:00
fix: createPubSubManager
This commit is contained in:
parent
a97240a10b
commit
e9679b6f86
@ -60,7 +60,7 @@ import { dataTemplate } from './middlewares/data-template';
|
||||
import validateFilterParams from './middlewares/validate-filter-params';
|
||||
import { Plugin } from './plugin';
|
||||
import { InstallOptions, PluginManager } from './plugin-manager';
|
||||
import { PubSubManager, PubSubManagerOptions } from './pub-sub-manager';
|
||||
import { createPubSubManager, PubSubManager, PubSubManagerOptions } from './pub-sub-manager';
|
||||
import { SyncManager } from './sync-manager';
|
||||
import { SyncMessageManager } from './sync-message-manager';
|
||||
|
||||
@ -1132,7 +1132,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
this._cli = this.createCLI();
|
||||
this._i18n = createI18n(options);
|
||||
this.syncManager = new SyncManager(this);
|
||||
this.pubSubManager = PubSubManager.create(this, {
|
||||
this.pubSubManager = createPubSubManager(this, {
|
||||
channelPrefix: this.name,
|
||||
...options.pubSubManager,
|
||||
});
|
||||
|
@ -25,23 +25,23 @@ export interface PubSubManagerSubscribeOptions {
|
||||
debounce?: number;
|
||||
}
|
||||
|
||||
export const createPubSubManager = (app: Application, options: PubSubManagerOptions) => {
|
||||
const pubSubManager = new PubSubManager(options);
|
||||
app.on('afterStart', async () => {
|
||||
await pubSubManager.connect();
|
||||
});
|
||||
app.on('afterStop', async () => {
|
||||
await pubSubManager.close();
|
||||
});
|
||||
return pubSubManager;
|
||||
};
|
||||
|
||||
export class PubSubManager {
|
||||
adapter: IPubSubAdapter;
|
||||
messageHandlers = new Map();
|
||||
subscribes = new Map();
|
||||
publisherId: string;
|
||||
|
||||
static create(app: Application, options: PubSubManagerOptions) {
|
||||
const pubSubManager = new PubSubManager(options);
|
||||
app.on('afterStart', async () => {
|
||||
await pubSubManager.connect();
|
||||
});
|
||||
app.on('afterStop', async () => {
|
||||
await pubSubManager.close();
|
||||
});
|
||||
return pubSubManager;
|
||||
}
|
||||
|
||||
constructor(protected options: PubSubManagerOptions = {}) {
|
||||
this.publisherId = uid();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user