middleware receive immutable versions of state and actions#63802
middleware receive immutable versions of state and actions#63802oatkiller merged 2 commits intoelastic:masterfrom
Conversation
|
Pinging @elastic/endpoint-app-team (Feature:Endpoint) |
30b22d2 to
85722d8
Compare
| return [indexPattern]; | ||
| } | ||
|
|
||
| return api => next => async (action: AppAction) => { |
There was a problem hiding this comment.
This will now be an Immutable version of AppAction.
| import { AppAction } from '../action'; | ||
|
|
||
| export const hostMiddlewareFactory: MiddlewareFactory<HostListState> = coreStart => { | ||
| return ({ getState, dispatch }) => next => async (action: AppAction) => { |
There was a problem hiding this comment.
This will now be an Immutable version of AppAction.
| ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ name: 'EndpointApp' }) | ||
| : compose; | ||
|
|
||
| export type Selector<S, R> = (state: S) => R; |
There was a problem hiding this comment.
moved type to types module. Code should be more readable now, and this type is relevant to the others there: ImmutableMiddleware, ImmutableMiddlewareAPI, ImmutableMidlewareFactory.
| * (should only be used for testing - example: to inject the action spy middleware) | ||
| */ | ||
| additionalMiddleware?: Array<ReturnType<MiddlewareFactory>>; | ||
| additionalMiddleware?: Array<ReturnType<ImmutableMiddlewareFactory>>; |
There was a problem hiding this comment.
@paul-tavares objections to replacing this with:
actionSpyMiddleware?: ActionSpyMiddleware
I don't think code outside of the store should dictating what middleware are used, how they are constructed, or what order they are applied in.
Theoretical example of what i'm concerned about:
Assume we learn that the actionSpyMiddleware should really come before all other middleware (seems reasonable, since by being added last, other middleware could decide not to pass an action on to the action spy.) If we move all 'additional middleware' to the beginning of the chain, and if there were other additional middleware (as opposed to just the spy) then that could cause issues.
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / kibana-xpack-agent / X-Pack Detection Engine API Integration Tests.x-pack/test/detection_engine_api_integration/security_and_spaces/tests/find_statuses·ts.detection engine api security and spaces enabled find_statuses should return a single rule status when a single rule is loaded from a find status with defaults addedStandard OutStack TraceHistory
To update your PR or re-run it, just comment with: |
…lastic#63802) Middleware receive state and actions, but they shouldn't mutate either. With this PR, middleware using the `substateMiddlewareFactory` helper will have this enforced via typescript. * replace `MiddlewareFactory` with `ImmutableMiddlewareFactory` * Added types: `ImmutableMiddleware` and `ImmutableMiddlewareAPI` which are similar to the ones built into redux but which enforce that state and actions aren't mutated (and which allow `Immutable` versions of actions to be dispatched. No changes to runtime code.
…bana into ingest-node-pipelines/privileges * 'feature/ingest-node-pipelines' of github.com:elastic/kibana: (126 commits) [SEARCH] Cleanup fetch soon (elastic#63320) skip flaky suite (elastic#58692) [Uptime] Refresh index and also show more info to user regardi… (elastic#62606) [Drilldowns] Fix back button by removing panels from url in dashboard in view mode (elastic#62415) [platform] serve plugins from /bundles/plugin:${id} [Alerting] Documentation for how to pre-configure connectors. (elastic#63807) skip flaky suite (elastic#63621) Revert "skip flaky suite (elastic#63747)" skip flaky suite (elastic#63747) [SIEM][Detections Engine] - Update rule.lists to be rule.exceptions_list (elastic#63717) [SIEM] Flaky test fix: Bump find_statuses timeout (elastic#63900) [Uptime] Add cert API request and runtime type checking (elastic#63062) [Lens] Allow table to scroll horizontally (elastic#63805) [Metrics UI] Allow users to create alerts from the central Alerts UI (elastic#63803) Migrate legacy maps licensing (x-pack/tilemap) to NP (elastic#63539) [Alerting] "Create alert" and alert list design improvements (elastic#63515) [Lens] Fix existence for dotted paths in _source (elastic#63752) Example plugins in X-Pack (elastic#63823) [ML] Migrate Mocha unit tests to Jest: migrate job utils and query utils tests (elastic#63775) Endpoint: middleware receive immutable versions of state and actions (elastic#63802) ...
|
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
…63802) (#63887) Middleware receive state and actions, but they shouldn't mutate either. With this PR, middleware using the `substateMiddlewareFactory` helper will have this enforced via typescript. * replace `MiddlewareFactory` with `ImmutableMiddlewareFactory` * Added types: `ImmutableMiddleware` and `ImmutableMiddlewareAPI` which are similar to the ones built into redux but which enforce that state and actions aren't mutated (and which allow `Immutable` versions of actions to be dispatched. No changes to runtime code. Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
Middleware receive state and actions, but they shouldn't mutate either. With this PR, middleware using the
substateMiddlewareFactoryhelper will have this enforced via typescript.MiddlewareFactorywithImmutableMiddlewareFactoryImmutableMiddlewareandImmutableMiddlewareAPIwhich are similar to the ones built into redux but which enforce that state and actions aren't mutated (and which allowImmutableversions of actions to be dispatched.No changes to runtime code.
See https://redux.js.org/faq/immutable-data for explanation of the pattern
Checklist
no runtime code changes intended
For maintainers