Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/get members 2173 #2174

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions __tests__/core/reflection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Binary file modified bun.lockb
Binary file not shown.
14 changes: 10 additions & 4 deletions src/core/mst-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down