Skip to content

Commit 821e01d

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 0ebde86 commit 821e01d

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

__tests__/core/reflection.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ test("reflection - model", () => {
6161
const reflection = getMembers(node)
6262
expect(reflection.name).toBe("AnonymousModel")
6363
expect(reflection.actions.includes("actionName")).toBe(true)
64+
expect(reflection.actions.includes("generatorAction")).toBe(true)
6465
expect(reflection.flowActions.includes("generatorAction")).toBe(true)
66+
expect(reflection.flowActions.includes("actionName")).toBe(false)
6567
expect(reflection.views.includes("viewName")).toBe(true)
68+
expect(reflection.views.includes("actionName")).toBe(false)
6669
expect(reflection.volatile.includes("volatileProperty")).toBe(true)
6770
expect(!!reflection.properties.users).toBe(true)
6871
expect(!!reflection.properties.isPerson).toBe(true)
@@ -166,6 +169,20 @@ test("reflection - members chained", () => {
166169
}
167170
}
168171
})
172+
.actions((self) => {
173+
function flowActionName() {
174+
return 1
175+
}
176+
return {
177+
flowActionName,
178+
generatorAction: flow(function* generatorAction() {
179+
const promise = new Promise((resolve) => {
180+
resolve(true)
181+
})
182+
yield promise
183+
})
184+
}
185+
})
169186
.views((self) => ({
170187
get viewName() {
171188
return 1
@@ -182,8 +199,15 @@ test("reflection - members chained", () => {
182199
expect(keys.includes("isPerson")).toBe(true)
183200
expect(reflection.actions.includes("actionName")).toBe(true)
184201
expect(reflection.actions.includes("anotherAction")).toBe(true)
202+
expect(reflection.actions.includes("flowActionName")).toBe(true)
203+
expect(reflection.actions.includes("generatorAction")).toBe(true)
204+
expect(reflection.flowActions.includes("generatorAction")).toBe(true)
205+
expect(reflection.flowActions.includes("flowActionName")).toBe(false)
185206
expect(reflection.views.includes("viewName")).toBe(true)
186207
expect(reflection.views.includes("anotherView")).toBe(true)
208+
expect(reflection.views.includes("actionName")).toBe(false)
209+
expect(reflection.views.includes("anotherAction")).toBe(false)
210+
expect(reflection.views.includes("flowActionName")).toBe(false)
187211
})
188212
test("reflection - conditionals respected", () => {
189213
let swap = true

bun.lockb

-103 KB
Binary file not shown.

src/core/mst-operations.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,16 @@ export function getMembers(target: IAnyStateTreeNode): IModelReflectionData {
891891
else reflected.volatile.push(key)
892892
return
893893
}
894-
if (descriptor.value._isMSTAction === true) reflected.actions.push(key)
895-
if (descriptor.value._isFlowAction === true) reflected.flowActions.push(key)
896-
else if (isObservableProp(target, key)) reflected.volatile.push(key)
897-
else reflected.views.push(key)
894+
if (descriptor.value._isFlowAction === true) {
895+
reflected.flowActions.push(key)
896+
}
897+
if (descriptor.value._isMSTAction === true) {
898+
reflected.actions.push(key)
899+
} else if (isObservableProp(target, key)) {
900+
reflected.volatile.push(key)
901+
} else {
902+
reflected.views.push(key)
903+
}
898904
})
899905
return reflected
900906
}

0 commit comments

Comments
 (0)