New source found from dndbeyond.com
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { HelperUtils } from "../engine/Helper";
|
||||
import { getCurrentRulesEngineConfig } from '../config/utils';
|
||||
export const subscriptionsMap = new Map();
|
||||
export class BaseManager {
|
||||
constructor(params = {}) {
|
||||
this.randomId = 0; // helpful for debugging
|
||||
@@ -50,3 +52,26 @@ export class BaseManager {
|
||||
};
|
||||
}
|
||||
}
|
||||
// manage subscriptions
|
||||
BaseManager.subscribeToUpdates = ({ onUpdate, shouldInit = true }) => {
|
||||
// TODO: maybe from lib.
|
||||
const mapKey = HelperUtils.generateGuid();
|
||||
// connect to redux for updates
|
||||
let unsubscribe;
|
||||
if (getCurrentRulesEngineConfig().store) {
|
||||
const store = getCurrentRulesEngineConfig().store;
|
||||
unsubscribe = store === null || store === void 0 ? void 0 : store.subscribe(() => {
|
||||
onUpdate();
|
||||
});
|
||||
}
|
||||
subscriptionsMap.set(mapKey, onUpdate);
|
||||
if (shouldInit) {
|
||||
onUpdate();
|
||||
}
|
||||
return () => {
|
||||
subscriptionsMap.delete(mapKey);
|
||||
if (unsubscribe) {
|
||||
unsubscribe();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user