-
-
Notifications
You must be signed in to change notification settings - Fork 2k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Consider making ngrx/entity framework-agnostic #2333
Comments
Here is a similar discussion about this idea ( #2283 ). |
We are using @ngrx/entity with ngxs, works great but it requires @ngrx/store as a dependency in package.json and we don't use @ngrx/store anywhere. |
Hey @markerikson, I think we might be able reasonably support that. What did you have in mind as far as changes to make that work? |
I'm not entirely sure what the desired implementation should actually look like. As mentioned, the only real framework-specific references here are the imports of It looks like the import of Perhaps For the Not sure what a suitable alternative would be here - a |
FWIW, I'm playing around with copy-pasting the The first tweaks were just replacing the Angular imports I've mentioned. I'm now looking at the update logic and seeing if there's ways to simplify it using Immer. (I've already updated |
Cool. Let us know how that goes. We'd still like to make this work and share some core code if possible. |
Sure. My first impression is that use of Immer would allow us to drop all the |
@markerikson WFIW, adding multiple deps freaks people out. e.g. Angular has the only dep right now, which is I'll all for reusable lib and would really like to see |
Right, there's multiple thoughts here. One is that if Another is that as I just found out, the logic in On that note, I just posted a comment over in the RTK issues about my initial attempts to fork-and-modify |
@markerikson I want to give you a lengthier response later and help make sharing @ngrx/entity a success. One thing I want to say now is that if you do pull in @ngrx/entity logic I'd shy away from refactoring the implementation details. One of the earliest design decisions I made with the library is that @ngrx/entity should be extremely fast under the hood. That's why the implementation is so bizarre looking. I never wanted someone opening an issue here blaming perf on @ngrx/entity. 😄 |
Sure. Nothing I'm doing so far is final - I'm just playing around with things atm. I am curious about:
|
GC pauses for managing
The implementations have always differed just enough that they had to be separate. @ngrx/entity sorts a collection at time of modification rather than in a selector. I've always had the itch to take this a step further and swap the sorted collection's implementation to use a heap and then sort the heap in a selector. Let me know what you find out with regards to Immer's perfomance here. I'm interested as well. |
Oh, another thing about the sorted collection implementation being different: IIRC when I created @ngrx/entity |
The Immer docs on overall perf are here: https://immerjs.github.io/immer/docs/performance Part of my observation is that while Immer will have additional overhead in comparison to doing things at the "raw JS" level (snicker), there are benefits in that:
No idea what actual benchmarks on this might look like. And yeah, I was looking at the sorting logic as I was reworking things, because my naive implementation wasn't stable. I noted that there's a test that explicitly reuses the same title twice for a |
One other API design thought: Right now, the on(UserActions.updateUsers, (state, { users }) => {
return adapter.updateMany(users, state);
}),
on(UserActions.mapUsers, (state, { entityMap }) => {
return adapter.map(entityMap, state);
}), It would be really nice if the adapter arguments were flipped, so that the adapter methods could be used as reducers directly. Similarly, it would be great if the outer adapter wrapper function could check to see if the second argument was a Flux Standard Action with an That would enable usage like: const usersAdapter = createEntityAdapter<User>();
const usersSlice = createSlice({
name: "users",
state: usersAdapter.getInitialState(),
reducers: {
userAdded: usersAdapter.addOne,
userRemoved: usersAdapter.removeOne,
// etc
}
}); |
This evening's experimentation:
I did run into some weird behavior with Immer, where nested That of course wouldn't be an issue if I hadn't just gone in and Immer-ified the guts of the entity logic. Other than that Immer issue, I really like where this is going. Problem is, I've just forked the original @MikeRyanDev : back to the perf thing. Did you have any particular benchmark scenarios you were running to do stress testing? Current code is here: Huh. One other note. Looks like the branch fails CI checks against TS 3.3 for some reason. |
Closing as resolved, but hopefully there's more collaboration in the future! |
Yes, absolutely! I got to watch the "State of NgRx" stream you did, and was both impressed by the amount of stuff y'all are doing and intrigued by how much of it is similar to what we're trying to do with RTK atm. We really ought to have some further discussions in the near future. |
@brandonroberts we probably need to revisit this issue. |
I agree. It would be super useful to have it available across both areas. Of course, I don't want to break existing users, or make it overly difficult to use it how they've been using it currently though. So if we can find a clean separation there, that would be great. |
I'll reopen this one for now. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Problem
The
@ngrx/entity
package provides some useful utilities for dealing with normalized state.Looking through the source files, most of the logic is actually not specific to NgRX. The type definitions and such seem very reusable, and it's almost completely framework-agnostic (as confirmed by @MikeRyanDev at https://twitter.com/MikeRyanDev/status/1216820265658789888 ).
The only framework-specific imports I can see are uses of
import { createSelector } from '@ngrx/store'
in a few files, andimport { isDevMode } from '@angular/core';
inutils.ts
.I'd be interested in reusing the logic from
@ngrx/entity
in Redux Toolkit, but in order for that to be possible, the Angular/NgRX-specific imports would need to be removed from this library.What is the feasibility of that happening?
We could always copy-paste the relevant code over to Redux Toolkit with appropriate citations, but it'd be nice to not have to reinvent the wheel over a couple of import statements.
If accepted, I would be willing to submit a PR for this feature
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
The text was updated successfully, but these errors were encountered: