Skip to content

Commit eec0026

Browse files
evinosheaforwardcoolsoftwaretyler
authored andcommitted
Fix/get members 2173 (#2174)
* 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]>
1 parent 5f63509 commit eec0026

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

__tests__/core/reflection.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ test("reflection - model", () => {
6060
const reflection = getMembers(node)
6161
expect(reflection.name).toBe("AnonymousModel")
6262
expect(reflection.actions.includes("actionName")).toBe(true)
63+
expect(reflection.actions.includes("generatorAction")).toBe(true)
6364
expect(reflection.flowActions.includes("generatorAction")).toBe(true)
65+
expect(reflection.flowActions.includes("actionName")).toBe(false)
6466
expect(reflection.views.includes("viewName")).toBe(true)
67+
expect(reflection.views.includes("actionName")).toBe(false)
6568
expect(reflection.volatile.includes("volatileProperty")).toBe(true)
6669
expect(!!reflection.properties.users).toBe(true)
6770
expect(!!reflection.properties.isPerson).toBe(true)
@@ -165,6 +168,20 @@ test("reflection - members chained", () => {
165168
}
166169
}
167170
})
171+
.actions((self) => {
172+
function flowActionName() {
173+
return 1
174+
}
175+
return {
176+
flowActionName,
177+
generatorAction: flow(function* generatorAction() {
178+
const promise = new Promise((resolve) => {
179+
resolve(true)
180+
})
181+
yield promise
182+
})
183+
}
184+
})
168185
.views((self) => ({
169186
get viewName() {
170187
return 1
@@ -181,8 +198,15 @@ test("reflection - members chained", () => {
181198
expect(keys.includes("isPerson")).toBe(true)
182199
expect(reflection.actions.includes("actionName")).toBe(true)
183200
expect(reflection.actions.includes("anotherAction")).toBe(true)
201+
expect(reflection.actions.includes("flowActionName")).toBe(true)
202+
expect(reflection.actions.includes("generatorAction")).toBe(true)
203+
expect(reflection.flowActions.includes("generatorAction")).toBe(true)
204+
expect(reflection.flowActions.includes("flowActionName")).toBe(false)
184205
expect(reflection.views.includes("viewName")).toBe(true)
185206
expect(reflection.views.includes("anotherView")).toBe(true)
207+
expect(reflection.views.includes("actionName")).toBe(false)
208+
expect(reflection.views.includes("anotherAction")).toBe(false)
209+
expect(reflection.views.includes("flowActionName")).toBe(false)
186210
})
187211
test("reflection - conditionals respected", () => {
188212
let swap = true

src/core/mst-operations.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -870,10 +870,16 @@ export function getMembers(target: IAnyStateTreeNode): IModelReflectionData {
870870
else reflected.volatile.push(key)
871871
return
872872
}
873-
if (descriptor.value._isMSTAction === true) reflected.actions.push(key)
874-
if (descriptor.value._isFlowAction === true) reflected.flowActions.push(key)
875-
else if (isObservableProp(target, key)) reflected.volatile.push(key)
876-
else reflected.views.push(key)
873+
if (descriptor.value._isFlowAction === true) {
874+
reflected.flowActions.push(key)
875+
}
876+
if (descriptor.value._isMSTAction === true) {
877+
reflected.actions.push(key)
878+
} else if (isObservableProp(target, key)) {
879+
reflected.volatile.push(key)
880+
} else {
881+
reflected.views.push(key)
882+
}
877883
})
878884
return reflected
879885
}

0 commit comments

Comments
 (0)