Add Studio V2 store with common, console and plugin reducers#1280
Add Studio V2 store with common, console and plugin reducers#1280GnsP wants to merge 1 commit intocdapio:developfrom
Conversation
a0fa859 to
50c706f
Compare
app/cdap/api/settings.ts
Outdated
| @@ -0,0 +1,27 @@ | |||
| /* | |||
| * Copyright © 2024 Cask Data, Inc. | |||
There was a problem hiding this comment.
nit: 2025 in all new files
There was a problem hiding this comment.
Yeah, will update the new files. Thanks for pointing out !
| * | ||
| * @returns The cloned copy of the object. | ||
| */ | ||
| export function cloneAndApplyMutation<T>(object: T, mutation: (draft: T) => any): T { |
There was a problem hiding this comment.
This is fine, but it could trigger re-renders on parts that haven't changed. Another approach would be to define the mutation (or call them helper) functions to return Partial<T>. Then you could use the spread operator to create the new state instance like normal.
There was a problem hiding this comment.
@njbriggs
Deep cloning the state may trigger re-renders. However returning a Partial<T> and using spread operator would not work for mutations with delete operator.
(Also, the Partial<T> in typescript performs a shallow partial conversion.)
I was considering the idea of using Proxy to intercept mutating operations (both set and delete) and capture them in a diff object, and then apply the diff on the actual state.
We can use the immer library (specifically, the immer.produce function) to do this; tradeoff -- it's 3Kb in size. Alternatively, we can implement a simpler version of immer.produce API, supporting only property mutations on plain objects and arrays.
There was a problem hiding this comment.
We already have immer in yarn.lock. We also have immutable. Would we be better off using one of those or even a Map for this piece of state?
There was a problem hiding this comment.
Then I think it would be better to use immer. It has a drop-in replacement for this function. Using immutable would require more changes.
50c706f to
2cccffc
Compare
Add Studio V2 store with common, console and plugin reducers
Description
As a part of migrating Studio to react, we start by moving the state stores to typescript and redux.
PR Type
Links
Jira: Jira issue #
Test Plan
Existing tests should pass.
Screenshots
NA