aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis
diff options
context:
space:
mode:
authorMichael Foiani <sotech117@michaels-mbp-3.devices.brown.edu>2022-04-28 17:10:04 -0400
committerMichael Foiani <sotech117@michaels-mbp-3.devices.brown.edu>2022-04-28 17:10:04 -0400
commit561890c44833dbd4725cb8d818edb9856a464066 (patch)
treeaeda0e122f24d644a3fecd0aaa27ac9ed427cf26 /src/client/apis
parent31ca80bf84b811aa6bdd39fe8bb16df8a0bb2944 (diff)
Remove demo code from CollectionFFView and implment observer call into recordingApi
Diffstat (limited to 'src/client/apis')
-rw-r--r--src/client/apis/recording/recordingApi.ts54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/client/apis/recording/recordingApi.ts b/src/client/apis/recording/recordingApi.ts
index 9ad7b5165..50d6f8038 100644
--- a/src/client/apis/recording/recordingApi.ts
+++ b/src/client/apis/recording/recordingApi.ts
@@ -1,6 +1,7 @@
import { CollectionFreeFormView } from "../../views/collections/collectionFreeForm";
import React, { useState } from "react";
-import { observable, observe } from "mobx";
+import { IReactionDisposer, observable, reaction } from "mobx";
+import { NumCast } from "../../../fields/Types";
type Movement = {
time: number,
@@ -39,6 +40,9 @@ export class RecordingApi {
this.currentPresentation = RecordingApi.NULL_PRESENTATION
this.isRecording = false;
this.absoluteStart = -1;
+
+ // used for tracking movements in the view frame
+ this.disposeFunc = null;
}
// little helper :)
@@ -79,6 +83,9 @@ export class RecordingApi {
this.isRecording = false
// clear absoluteStart
this.absoluteStart = -1
+
+ // clear the disposeFunc
+ this.disposeFunc = null
}
public pause = (): Error | undefined => {
@@ -117,7 +124,7 @@ export class RecordingApi {
return { ...this.currentPresentation }
}
- public trackMovements = (panX: number, panY: number): Error | undefined => {
+ private trackMovements = (panX: number, panY: number): Error | undefined => {
// ensure we are recording
if (!this.isRecording) {
console.error('[recordingApi.ts] pause() failed: recording is paused()')
@@ -151,13 +158,42 @@ export class RecordingApi {
})
}
- // observer that can be updated to track the relevant FreeFormView
- // public setFreeFormView = (view: CollectionFreeFormView): void => {
- // observe(view, 'Document', (change) => {
- // if (change.name === '_panX') {
- // this.trackMovements(view.Document._panX, view.Document._panY)
- // }
- // }
+ // instance variable for the FFView
+ private disposeFunc: IReactionDisposer | null;
+
+ // set the FFView that will be used in a reaction to track the movements
+ public setRecordingFFView = (view: CollectionFreeFormView): void => {
+ // set the view to the current view
+ if (view === null) return;
+
+ //this.recordingFFView = view;
+ // set the reaction to track the movements
+ this.disposeFunc = reaction(
+ () => ({ x: NumCast(view.Document.panX, -1), y: NumCast(view.Document.panY, -1) }),
+ (res) => (res.x !== -1 && res.y !== -1) && this.trackMovements(res.x, res.y)
+ )
+ }
+
+ // call on dispose function to stop tracking movements
+ public removeRecordingFFView = (): void => {
+ this.disposeFunc?.();
+ this.disposeFunc = null;
+ }
+
+
+ // export let pres: Map<CollectionFreeFormView, IReactionDisposer> = new Map()
+
+ // export function AddRecordingFFView(ffView: CollectionFreeFormView): void {
+ // pres.set(ffView,
+ // reaction(() => ({ x: ffView.panX, y: ffView.panY }),
+ // (pt) => RecordingApi.trackMovements(ffView, pt.x, pt.y)))
+ // )
+ // }
+
+ // export function RemoveRecordingFFView(ffView: CollectionFreeFormView): void {
+ // const disposer = pres.get(ffView);
+ // disposer?.();
+ // pres.delete(ffView)
// }
} \ No newline at end of file