Refactor init command to be a dispatchable init action#1643
Conversation
…omAppDefAsync method Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/89334cd8-f975-4147-bb71-9fd2c4256113 Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
…promise from initAppFromAppDef thunk, update tests to use await Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/89334cd8-f975-4147-bb71-9fd2c4256113 Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Bundle Size Report ✅ PASS
Top Changes
Generated by build-size-diff Commit: e794089 |
|
@copilot The intent was correct (a new dispatchable action that takes an appdef payload), but the implementation was completely wrong. For one, this new initAppFromAppDef action is only referenced by tests, but not in actual app code. I wanted the existing init infrastructure to fetch the appdef and then route through to this new action with the fetched appdef. Secondly, I wanted this new action to not take an IViewerInitCommand argument. This new IViewerInitCommand.runFromAppDefAsync method you have delegated the run logic to from within this new initAppFromAppDef action, I was expecting you to inline all the implementation logic. |
…tCommand internally, route via setViewer/app.tsx Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/1b7c55cb-ad79-485f-a19a-acda593349d7 Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
…ve comments, use afterEach for spy cleanup Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/1b7c55cb-ad79-485f-a19a-acda593349d7 Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Addressed in commits The key changes:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot I am still not seeing the material gains with this refactoring you have done. Let me restate the high-level goals: I want a new thunked action The existing Our tests around this thunked action should verify the expected redux store state after a dispatched INIT_APP from a given source appDef + extra parameters. The purpose of this refactoring is to pave way for #217 since our new thunked action takes the prepared appDef, whether this appDef went through deArrayification or not is irrelevant to this new thunked action. That way we can easily verify that a dispatched init of this new thunked action with an appDef that did not go through deArrayification produces the same redux store state as an appDef that did go through deArrayification. This way, we have greater confidence in ripping out (or code-split out) the hefty deArrayification code as part of #217 once we have confirmation that both appDefs yield the same init result through this new thunked action. Pls start from the original branching point again and re-implement this change with this revised understanding in mind. |
Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/1e1794cd-9272-4502-9a5f-56de9ed7cf56 Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
…/runFromAppDefAsync on IViewerInitCommand Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/1e1794cd-9272-4502-9a5f-56de9ed7cf56 Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Implemented in commit The new export function initAppFromAppDef(
cmd: IViewerInitCommand,
options: IInitAppLayout,
appDef: ApplicationDefinition,
viewer: IMapProviderContext
): ReduxThunkedActionAll initialization logic (locale init, session management, runtime-map creation, toolbar parsing, payload overrides, Routing through existing init infrastructure:
Tests verify the expected redux store state: 7 tests for Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot I wanted the initLayout thunked action gone and its call-site to be refactored to dispatch the replacement thunked action instead. |
…after loadResourceAsync Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/4d58274d-bf3a-4e6b-9d47-a106d30f3900 Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Done in commit
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot I don't like this inline thunked action replacement. Is this solely because the loading of the appDef is tied to needing to call the added loadResourceAsync() on the IViewerInitCommand? If so, then rip that method out to its own non-dispatchable function. I want the resource/appdef loading part fully decoupled from any thunked action dispatch. |
…adViewerResourceAsync Agent-Logs-Url: https://github.com/jumpinjackie/mapguide-react-layout/sessions/a9a9b287-70dc-438c-93c6-a2f25fca405b Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Done in commit
|
The viewer initialization flow required callers to construct an
IViewerInitCommandobject that both fetches the appdef resource and builds theINIT_APPpayload — there was no way to initialize directly from an already-loadedApplicationDefinition.Changes
IViewerInitCommandinterface (src/actions/init-command.ts)runFromAppDefAsync(appDef, options)method that builds the fullIInitAppActionPayloadfrom a pre-loadedApplicationDefinition, handling locale init, session setup/reuse, runtime-map creation, toolbar parsing, and selection-set recovery.loadResourceAsyncis not on this interface — resource loading is fully decoupled from the interface and from any Redux dispatch mechanism.IInitAsyncOptions(src/actions/init.ts)sessionWasReused?flag for threading session context intorunFromAppDefAsync, distinguishing a freshly-created session from a genuinely reused one.DefaultViewerInitCommand(src/actions/init-mapguide.ts)loadResourceAsyncas a concrete public method — handles all resource-id cases (appdef.json, URL-to-appdef, MapGuideApplicationDefinition,WebLayout, function-resourceId), creates a session lazily when required, and returns aLoadedResourcediscriminated union ({ kind: 'appdef', appDef, sessionOptions }|{ kind: 'weblayout', payload }).runFromAppDefAsync— inlines all initialization logic (locale, session management, runtime-map creation, toolbar parsing, selection recovery).sessionWasReusedis inferred fromoptions.sessionWasReused ?? !!options.session.runAsyncrefactored to delegate throughloadResourceAsync+runFromAppDefAsyncfor backward compatibility.New standalone
loadViewerResourceAsyncfunction (src/actions/init-mapguide.ts)loadViewerResourceAsync(cmd: DefaultViewerInitCommand, options: IInitAsyncOptions): Promise<LoadedResource>.cmd.attachClient(...)and then call this function directly.New
initAppFromAppDefthunked action (src/actions/init.ts)initAppFromAppDef(cmd: IViewerInitCommand, options: IInitAppLayout, appDef: ApplicationDefinition, viewer: IMapProviderContext): ReduxThunkedAction.cmd.runFromAppDefAsync, applies payload overrides (initialView,initialActiveMap,appSettingsmerge) via the extractedapplyInitPayloadOverrideshelper, dispatchesINIT_APP, and callsonInit(viewer).INIT_ERRORis dispatched ifrunFromAppDefAsyncrejects.initLayoutremoved (src/actions/init.ts)initLayoutis removed entirely.processAndDispatchInitErroris now exported.app.tsx(src/containers/app.tsx)IAppProps.initCommandtype narrowed fromIViewerInitCommandtoDefaultViewerInitCommandso thatloadViewerResourceAsynccan be called directly.IAppDispatch.initLayoutremoved from the interface.useConfiguredAgentUri()anduseConfiguredAgentKind()hooks are called at the component body level to obtain agent config from Redux state.useEffectcallsloadViewerResourceAsync(initCommand, opts)directly (no inline thunk), attaches the client beforehand ifagentUri/agentKindare available, then dispatchesinitAppFromAppDeffor AppDef resources orINIT_APPinline for WebLayout resources.Public API (
src/entries/library.tsx)initAppFromAppDefadded to library exports.Tests
initAppFromAppDefintest/actions/init.spec.ts: INIT_APP dispatch, INIT_ERROR on rejection,initialView/initialActiveMapoverrides,onInitcallback,appSettingsmerge, and client attachment behavior.DefaultViewerInitCommand.runFromAppDefAsyncintest/actions/init-mapguide.spec.ts: payload structure from a real stateless AppDef with a subject-layer map, andsessionWasReusedinference logic (no session, provided session without flag, provided session with explicitfalse).test/containers/app-component.spec.tsx: hooks mock includesuseConfiguredAgentUri/useConfiguredAgentKind; verifies thatloadResourceAsyncis called with the correct init options built from URL state and props, and thatinitAppFromAppDefis subsequently dispatched with the loaded appDef.