diff --git a/__tests__/core/reflection.test.ts b/__tests__/core/reflection.test.ts index 34f33241e..a8d1767b8 100644 --- a/__tests__/core/reflection.test.ts +++ b/__tests__/core/reflection.test.ts @@ -61,8 +61,11 @@ test("reflection - model", () => { const reflection = getMembers(node) expect(reflection.name).toBe("AnonymousModel") expect(reflection.actions.includes("actionName")).toBe(true) + expect(reflection.actions.includes("generatorAction")).toBe(true) expect(reflection.flowActions.includes("generatorAction")).toBe(true) + expect(reflection.flowActions.includes("actionName")).toBe(false) expect(reflection.views.includes("viewName")).toBe(true) + expect(reflection.views.includes("actionName")).toBe(false) expect(reflection.volatile.includes("volatileProperty")).toBe(true) expect(!!reflection.properties.users).toBe(true) expect(!!reflection.properties.isPerson).toBe(true) @@ -166,6 +169,20 @@ test("reflection - members chained", () => { } } }) + .actions((self) => { + function flowActionName() { + return 1 + } + return { + flowActionName, + generatorAction: flow(function* generatorAction() { + const promise = new Promise((resolve) => { + resolve(true) + }) + yield promise + }) + } + }) .views((self) => ({ get viewName() { return 1 @@ -182,8 +199,15 @@ test("reflection - members chained", () => { expect(keys.includes("isPerson")).toBe(true) expect(reflection.actions.includes("actionName")).toBe(true) expect(reflection.actions.includes("anotherAction")).toBe(true) + expect(reflection.actions.includes("flowActionName")).toBe(true) + expect(reflection.actions.includes("generatorAction")).toBe(true) + expect(reflection.flowActions.includes("generatorAction")).toBe(true) + expect(reflection.flowActions.includes("flowActionName")).toBe(false) expect(reflection.views.includes("viewName")).toBe(true) expect(reflection.views.includes("anotherView")).toBe(true) + expect(reflection.views.includes("actionName")).toBe(false) + expect(reflection.views.includes("anotherAction")).toBe(false) + expect(reflection.views.includes("flowActionName")).toBe(false) }) test("reflection - conditionals respected", () => { let swap = true diff --git a/bun.lockb b/bun.lockb index e8f417728..9662c599e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/core/mst-operations.ts b/src/core/mst-operations.ts index 54cd6f0c7..7ac1f3440 100644 --- a/src/core/mst-operations.ts +++ b/src/core/mst-operations.ts @@ -891,10 +891,16 @@ export function getMembers(target: IAnyStateTreeNode): IModelReflectionData { else reflected.volatile.push(key) return } - if (descriptor.value._isMSTAction === true) reflected.actions.push(key) - if (descriptor.value._isFlowAction === true) reflected.flowActions.push(key) - else if (isObservableProp(target, key)) reflected.volatile.push(key) - else reflected.views.push(key) + if (descriptor.value._isFlowAction === true) { + reflected.flowActions.push(key) + } + if (descriptor.value._isMSTAction === true) { + reflected.actions.push(key) + } else if (isObservableProp(target, key)) { + reflected.volatile.push(key) + } else { + reflected.views.push(key) + } }) return reflected }