ant-design-blazor/components/core/JsInterop/modules/stateProvider.ts
Andrzej Bakun 29e3ce3583 refactor(interop): reorganization into classes and typescript tests (#1791)
* fix(module:interop): reorganization into classes

* comments clean-up

* Add typescript test project

* fix: sync with pull request #1765: support drag

* github test action fix attempt

* tests: jsinterop test mock fix

* codecov added to ts tests

* add generated split js to gitignore

* fix: coverage github action

Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-07-29 22:45:47 +08:00

32 lines
881 B
TypeScript

import { eventCallback } from './dom/types'
//Singleton
export class State {
private static instance: State;
//Stores references to dot net objects (components wrapped in DotNetObjectReference)
objReferenceDict: { [key: string]: any } = {};
//All object references must later be disposed by JS code or by .NET code.
disposeObj(objReferenceName) {
delete this.objReferenceDict[objReferenceName];
}
//Stores callback for events based on a key. Needed when
//Event needs to be removed - the callback can be retrieved and
//used to remove the event in question
eventCallbackRegistry: { [key: string]: eventCallback} = {};
oldBodyCacheStack = [];
private constructor() { }
static getInstance() {
if (!this.instance) {
this.instance = new State();
}
return this.instance;
}
}
export const state = State.getInstance();