Skip to content

Commit

Permalink
Fix/get members 2173 (#2174)
Browse files Browse the repository at this point in the history
* test: add failing test to confirm changed behavior issue-2173

* fix: correct getMembers actions/flowactions categorization issue-2173

* chore: update if/else formatting in getMembers for posterity issue-2173

* test: add explicit expect for flow action is added to actions in getMembers issue-2173

* test: add flow action testing to reflection - members chained test issue-2173

---------

Co-authored-by: Evin O'Shea <[email protected]>
  • Loading branch information
2 people authored and coolsoftwaretyler committed Apr 17, 2024
1 parent 5f63509 commit eec0026
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
24 changes: 24 additions & 0 deletions __tests__/core/reflection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,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)
Expand Down Expand Up @@ -165,6 +168,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
Expand All @@ -181,8 +198,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
Expand Down
14 changes: 10 additions & 4 deletions src/core/mst-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,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
}
Expand Down

0 comments on commit eec0026

Please sign in to comment.