Comments (9)
@markostanimirovic is there any workaround in the meantime?
You can do:
const myEntity = { ...entityMap()['tmp_id'], id: 'real_id' };
patchState(store, removeEntity('tmp_id'), addEntity(myEntity));
from platform.
I'm also not a big fan of updating the ID. 👀 That's the reason why the current implementation does not support it. On the other hand, @ngrx/entity
provides the ability to change the ID, so this change may land for compatibility.
from platform.
so this change may land for compatibility
Thank you @markostanimirovic
IMO changing an ID is doable but is a very bad idea and should not be done
I'm also not a big fan of updating the ID.
I understand your concerns, but there are legitimate cases where it may be necessary to create a temporary ID. If you guys are interested, I can go into this topic in more detail.
However, I think the decision of what do to with the id belongs to the developer or team ✌️☮️
from platform.
This will be a breaking change for entities whose identifier name is different from id
. In other words, it will be required to pass idKey
in case of a custom identifier for all update...
entity updaters which is not the case with the current implementation.
Even though the @ngrx/signals
package is in a developer preview, we try to minimize breaking changes, so there is a chance that this change will land in v18 instead of v17.x.
from platform.
I can confirm this behaviour. We have the same expectation as @xSirrioNx .
Additionally to store.entityMap, store.ids() contains also the old tmp id instead of the new id.
from platform.
IMO changing an ID is doable but is a very bad idea and should not be done, as it's a design mistake to change IDs ever.
IDs are meant to be immutable (never change), as they identify entities across systems. Guessing from your code, there is some time span where you don't have any id
. Either don't put the object into the store (if the backend hasn't assigned an id, it's NOT an entity YET) - or make the frontend assign a GUID and send it to the backend. I'd go with putting the entity into the store after it's returned from the server (with ID)
to make types bullet proof, I'd go with "strict unions" - disable the ability to pass the id
at all:
declare function disable_id_from_partial<T>(withoutId: Partial<T> & { id?: undefined }): void;
disable_id_from_partial<Todo>({ name: 'some_real_name' }) // ✅ OK
disable_id_from_partial<Todo>({ id: 'uuid', name: 'some_real_name' }) // ❌ ID - NOT OT
from platform.
So we can add separeted method to change entity ID
For example:
patchState(store,
updateEntity({ id: 'old_id', changes: {id: 'new_id'}}),
changeEntityId('old_id', 'new_id')
)
from platform.
@markostanimirovic is there any workaround in the meantime?
from platform.
@markostanimirovic thanks.
from platform.
Related Issues (20)
- Add JSDoc for `mapResponse` operator HOT 1
- Allow generics in ngrx signals withEntites HOT 2
- RFC: `signalStoreFeature` and access to Store HOT 4
- How do you add a Pipe provider to a SignalStore, and SignalStore provider to a Service?
- NgRx Signal Store: functions inside OnInit hook, don't run when store is injected into normal service HOT 1
- Adding new withMethods causes NgRx signal store to return store: {[p:string]: function():?) HOT 4
- Do 'createSelector' can access to the previous value of the state inside the function ?
- PSA: Angular v18 and NgRx v18 HOT 6
- NGRX Signals Needs support for Angular 18 HOT 1
- Remove effects/concatLatestFrom docs HOT 4
- Remove component-store/tapResponse docs
- ngrx.io dns is down HOT 3
- ngrx.io server is down HOT 1
- Add support for ESLint v9
- computed not re-calculating if signal is inside function HOT 1
- [Bug] @ngrx/signals: DeepSignal is not exported HOT 3
- UpdateStr and UpdateNum are not export in index HOT 2
- Document ESLint v9 support
- Add v18 migration guide
- Add eslint rule for signalState and withState
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from platform.