Skip to content

Commit

Permalink
fix: usage without scenesDerives and avoid double get if data is real…
Browse files Browse the repository at this point in the history
…ly null
  • Loading branch information
kravetsone committed Dec 26, 2024
1 parent 3b5d4b7 commit 3da3225
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gramio/scenes",
"version": "0.2.0",
"version": "0.2.1",
"description": "Scenes plugin for GramIO",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ export function scenes(scenes: AnyScene[], options?: ScenesOptions) {
const key = `@gramio/scenes:${context.from?.id ?? 0}`;
const sceneData =
// @ts-expect-error PRIVATE KEY USAGE
context.scene["~"]?.data ??
(await storage.get<ScenesStorageData<unknown, unknown>>(key));
"scene" in context && "~" in context.scene
? // @ts-expect-error PRIVATE KEY USAGE
context.scene["~"]?.data
: await storage.get<ScenesStorageData<unknown, unknown>>(key);

if (!sceneData) return next();

Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function getInActiveSceneHandler<
sceneData.state = Object.assign(sceneData.state, state);

// sceneData.stepId.
// console.log("UPDATE", sceneData.state);

if (options?.step !== undefined)
await stepDerives.go(options.step, options.firstTime);
Expand Down Expand Up @@ -133,7 +134,7 @@ export function getStepDerives(
storageData.stepId = stepId;
storageData.firstTime = firstTime;
// console.log("Oh we go to step", stepId);
await storage.set(key, storageData);
// await storage.set(key, storageData);
//@ts-expect-error
context.scene = getInActiveSceneHandler(
context,
Expand Down

0 comments on commit 3da3225

Please sign in to comment.