[WC-3420] Pusher initial implementation#2224
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
AI Code Review
What was reviewed
Skipped (out of scope): Findings🔶 Medium — Stale
|
# Conflicts: # pnpm-lock.yaml
AI Code Review
What was reviewed
Skipped (out of scope): CI check results could not be retrieved automatically. Findings🔶 Medium — Placeholder test file with no real coverageFile: import { render } from "@testing-library/react";
import { actionValue } from "@mendix/widget-plugin-test-utils";
import { PusherListener } from "../utils/PusherListener";
describe("PusherListener", () => {
it("throws when subscribe is called before initialize", () => {
const listener = new PusherListener({ key: "k", cluster: "eu", authEndpoint: "/auth", csrfToken: "t" });
expect(() => listener.subscribe({ entityName: "E", guid: "1", eventName: "change", onEvent: jest.fn() }))
.toThrow("not initialized");
});
it("calls onEvent when the bound event fires", () => {
// mock pusher-js, assert bind + trigger
});
});
describe("Pusher component", () => {
it("renders without crashing when objectSource is unavailable", () => {
// render with loading/unavailable mxObjectInfo
});
});🔶 Medium — Stale
|
| const [config, setConfig] = useState<PusherConfig | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| let active = true; |
There was a problem hiding this comment.
I don't think we need active here. We can use ctrl.signal.aborted flag
| /** | ||
| * Creates and initializes a PusherListener | ||
| */ | ||
| export function usePusherListener(): PusherListener | null { |
There was a problem hiding this comment.
I think usePusherListener and useFetchPusherConfig should be merge into single factory. They have dependency that seems separated just for seek of hooks, don't think it adds lot of value. useFetchPusherConfig don't have any args. We can create one clean factory that fetches config, init the instance and returns it wrapped in promise. This way whole factory can be passed to useState and we have ether instance or null. This way we have less coupling with react.
| * Initialize Pusher connection | ||
| * Should be called once on widget mount | ||
| */ | ||
| initialize(): void { |
There was a problem hiding this comment.
I think this code belongs to constructor. Init just adds extra step for no reason.
| * Automatically unsubscribes from previous channel if different | ||
| */ | ||
| subscribe(config: SubscriptionConfig): void { | ||
| if (!this.pusher) { |
There was a problem hiding this comment.
If we move init code to constructor this prop can be set to not-nullable
| } | ||
| } | ||
|
|
||
| private buildChannelName(entityName: string, guid: string): string { |
There was a problem hiding this comment.
I think this should be a getter
| } | ||
|
|
||
| export function useMxObjectInfo(objectSource: DynamicValue<ObjectItem>): MxObjectInfo | undefined { | ||
| const object = (objectSource as any)?.value as ObjectItem | undefined; |
There was a problem hiding this comment.
Are we going to keep this any?
| }, []); | ||
|
|
||
| // Setup stable subscription config | ||
| const subscription = useMemo(() => { |
There was a problem hiding this comment.
NIT: I would extract this block to small function for better testing
Pull request type
Description