Git Product home page Git Product logo

Comments (9)

markostanimirovic avatar markostanimirovic commented on June 9, 2024 2

@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.

markostanimirovic avatar markostanimirovic commented on June 9, 2024 1

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.

SerkanSipahi avatar SerkanSipahi commented on June 9, 2024 1

so this change may land for compatibility

Thank you @markostanimirovic

@markostanimirovic @ducin

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.

markostanimirovic avatar markostanimirovic commented on June 9, 2024 1

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.

SerkanSipahi avatar SerkanSipahi commented on June 9, 2024

@markostanimirovic

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.

ducin avatar ducin commented on June 9, 2024

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.

xSirrioNx avatar xSirrioNx commented on June 9, 2024

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.

SerkanSipahi avatar SerkanSipahi commented on June 9, 2024

@markostanimirovic is there any workaround in the meantime?

from platform.

SerkanSipahi avatar SerkanSipahi commented on June 9, 2024

@markostanimirovic thanks.

from platform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.