@netless/app-slide 0.2.104 → 0.2.105-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/app-slide",
3
- "version": "0.2.104",
3
+ "version": "0.2.105-beta.0",
4
4
  "main": "dist/main.cjs.js",
5
5
  "module": "dist/main.es.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -113,7 +113,9 @@ export interface AppResult {
113
113
  translateView: (offsetX: number, offsetY: number) => void;
114
114
  }
115
115
 
116
- const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
116
+ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> & {
117
+ teardown(context: import("@netless/window-manager").AppContext): void;
118
+ } = {
117
119
  kind: "Slide",
118
120
  setup(context) {
119
121
  console.log("[Slide] setup @ " + version);
@@ -247,7 +249,14 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
247
249
  });
248
250
  }
249
251
 
250
- context.emitter.on("destroy", () => {
252
+ let disposed = false;
253
+ let offDestroy: (() => void) | undefined;
254
+ const teardown = () => {
255
+ if (disposed) return;
256
+ disposed = true;
257
+ const removeDestroy = offDestroy;
258
+ offDestroy = undefined;
259
+ removeDestroy?.();
251
260
  log("[Slide] destroy", context.appId);
252
261
  if (useFreezer) apps.delete(context.appId);
253
262
  sideEffect.flushAll();
@@ -255,10 +264,14 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
255
264
  docsViewer.destroy();
256
265
  docsViewer = null;
257
266
  }
258
- });
267
+ };
268
+ offDestroy = context.emitter.on("destroy", teardown);
259
269
 
260
270
  docsViewer.mount();
261
271
 
272
+ (SlideApp as any).__teardownByContext ||= new WeakMap<object, () => void>();
273
+ (SlideApp as any).__teardownByContext.set(context, teardown);
274
+
262
275
  return {
263
276
  onScaleChanged: (cb: (scale: number) => void) => {
264
277
  if (!docsViewer) {
@@ -384,6 +397,10 @@ const SlideApp: NetlessApp<Attributes, MagixEvents, AppOptions, AppResult> = {
384
397
  },
385
398
  };
386
399
  },
400
+ teardown(context) {
401
+ (SlideApp as any).__teardownByContext?.get(context)?.();
402
+ (SlideApp as any).__teardownByContext?.delete(context);
403
+ },
387
404
  };
388
405
 
389
406
  export default SlideApp;