Skip to content

Visualize Your Ideas With Code

refactor: remove yield symbols

aarthificial49a4bd040dab
diff --git a/src/Scene.ts b/src/Scene.ts
index f7bd7e61..b4acce45 100644
--- a/src/Scene.ts
+++ b/src/Scene.ts
@@ -12,7 +12,6 @@ import {Group} from 'konva/lib/Group';
import {Shape} from 'konva/lib/Shape';
import {SceneTransition} from './transitions';
import {decorate, KonvaNode, threadable} from './decorators';
-import {PROJECT, SCENE} from './symbols';
import {SimpleEventDispatcher} from 'strongly-typed-events';
import {setScene} from './utils';
@@ -134,10 +133,6 @@ export class Scene extends Group {
if (isPromise(result.value)) {
const value = await result.value;
result = this.runner.next(value);
- } else if (result.value === PROJECT) {
- result = this.runner.next(this.project);
- } else if (result.value === SCENE) {
- result = this.runner.next(this);
} else {
console.log('Invalid value: ', result.value);
result = this.runner.next();
diff --git a/src/animations/scheduling.ts b/src/animations/scheduling.ts
index 950a1f93..3940f62e 100644
--- a/src/animations/scheduling.ts
+++ b/src/animations/scheduling.ts
@@ -1,8 +1,8 @@
import type {Project} from '../Project';
import type {Scene} from '../Scene';
import {decorate, threadable} from '../decorators';
-import {PROJECT, SCENE} from '../symbols';
import {ThreadGenerator} from '../threading';
+import {useProject, useScene} from '../utils';
decorate(waitUntil, threadable());
export function waitUntil(
@@ -17,7 +17,7 @@ export function* waitUntil(
targetTime: number | string = 0,
after?: ThreadGenerator,
): ThreadGenerator {
- const scene: Scene = yield SCENE;
+ const scene = useScene();
const frames =
typeof targetTime === 'string'
? scene.getFrameEvent(targetTime)
@@ -37,7 +37,7 @@ export function* waitFor(
seconds = 0,
after?: ThreadGenerator,
): ThreadGenerator {
- const project: Project = yield PROJECT;
+ const project = useProject();
const frames = project.secondsToFrames(seconds);
const startFrame = project.frame;
while (project.frame - startFrame < frames) {
diff --git a/src/symbols.ts b/src/symbols.ts
index 59730bae..b3847608 100644
--- a/src/symbols.ts
+++ b/src/symbols.ts
@@ -1,4 +1,2 @@
export const ANIMATE = Symbol('ANIMATE');
-export const PROJECT = Symbol('PROJECT');
-export const SCENE = Symbol('SCENE');
export const NODE_ID = Symbol.for('NODE_ID');
\ No newline at end of file
diff --git a/src/transitions/slideTransition.ts b/src/transitions/slideTransition.ts
index 0543ba8a..5739a0cc 100644
--- a/src/transitions/slideTransition.ts
+++ b/src/transitions/slideTransition.ts
@@ -2,15 +2,15 @@ import type {Project} from '../Project';
import type {SceneTransition} from './SceneTransition';
import {Direction, originPosition} from '../types';
-import {PROJECT} from '../symbols';
import {easeInOutCubic, tween, vector2dTween} from '../tweening';
import {ThreadGenerator} from '../threading';
+import { useProject } from "../utils";
export function slideTransition(
direction: Direction = Direction.Top,
): SceneTransition {
return function* (next, previous): ThreadGenerator {
- const project: Project = yield PROJECT;
+ const project = useProject();
const position = originPosition(
direction,
project.width(),
diff --git a/src/tweening/tween.ts b/src/tweening/tween.ts
index db6a35e4..e159bf55 100644
--- a/src/tweening/tween.ts
+++ b/src/tweening/tween.ts
@@ -1,7 +1,7 @@
import {decorate, threadable} from '../decorators';
import type {Project} from '../Project';
-import {PROJECT} from '../symbols';
import {ThreadGenerator} from '../threading';
+import { useProject } from "../utils";
decorate(tween, threadable());
export function* tween(
@@ -9,7 +9,7 @@ export function* tween(
onProgress: (value: number, time: number) => void,
onEnd?: (value: number, time: number) => void,
): ThreadGenerator {
- const project = (yield PROJECT) as Project;
+ const project = useProject();
const frames = project.secondsToFrames(duration);
let startFrame = project.frame;
let value = 0;
diff --git a/src/utils/index.ts b/src/utils/index.ts
index b2e883a6..f19142be 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -2,3 +2,4 @@ export * from './slide';
export * from './pop';
export * from './useRef';
export * from './useScene';
+export * from './useProject';
diff --git a/src/utils/useProject.ts b/src/utils/useProject.ts
new file mode 100644
index 00000000..7d2c7753
--- /dev/null
+++ b/src/utils/useProject.ts
@@ -0,0 +1,5 @@
+import { useScene } from "./useScene";
+
+export function useProject() {
+ return useScene().project;
+}
\ No newline at end of file