-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
middleware receive immutable versions of state and actions #63802
middleware receive immutable versions of state and actions #63802
Conversation
Pinging @elastic/endpoint-app-team (Feature:Endpoint) |
30b22d2
to
85722d8
Compare
@@ -29,7 +31,7 @@ export const alertMiddlewareFactory: MiddlewareFactory<AlertListState> = (coreSt | |||
return [indexPattern]; | |||
} | |||
|
|||
return api => next => async (action: AppAction) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will now be an Immutable
version of AppAction.
|
||
export const hostMiddlewareFactory: MiddlewareFactory<HostListState> = coreStart => { | ||
return ({ getState, dispatch }) => next => async (action: AppAction) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will now be an Immutable version of AppAction.
import { EndpointPluginStartDependencies } from '../../../plugin'; | ||
|
||
const composeWithReduxDevTools = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ | ||
? (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved type to types
module. Code should be more readable now, and this type is relevant to the others there: ImmutableMiddleware
, ImmutableMiddlewareAPI
, ImmutableMidlewareFactory
.
@@ -66,7 +47,7 @@ export const appStoreFactory: (middlewareDeps?: { | |||
* Any additional Redux Middlewares | |||
* (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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 Out
Stack Trace
History
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
substateMiddlewareFactory
helper will have this enforced via typescript.MiddlewareFactory
withImmutableMiddlewareFactory
ImmutableMiddleware
andImmutableMiddlewareAPI
which are similar to the ones built into redux but which enforce that state and actions aren't mutated (and which allowImmutable
versions 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