[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:
When I update the active entity the id property on the state object receives a copy of the new entity state
The entity should be updated with the values from the partial object.
import { Injectable } from "@angular/core";
import { ActiveState, EntityState, EntityStore, ID, StoreConfig, transaction } from "@datorama/akita";
import { NGXLogger } from "ngx-logger";
import { FormStatus, IForm } from "@models";
export interface IFormsState extends EntityState<IForm>, ActiveState { }
@Injectable()
@StoreConfig({ name: "forms" })
export class FormsStore extends EntityStore<IFormsState, IForm> {
constructor(private logger: NGXLogger) {
super({ active: null });
}
@transaction()
public startForm(formId: ID) {
this.setActive(formId);
this.updateActive({ status: FormStatus.inProgress });
}
}
Original entity JSON:
{
"isValid": false,
"id": 1,
"status": -1,
"consentConfirmations": [
{
"hasAcknowledged": false,
"text": "Display text 1"
},
{
"hasAcknowledged": false,
"text": "Display text 2"
},
{
"hasAcknowledged": false,
"text": "Display text 3"
}
],
"displayName": "Electronic Consent",
"footerText": "Awesome footer text",
"ordinalPosition": 0,
"formComponentType": "consent",
"text": "Display text here"
}
After calling update the selectActive method from the entity query returns this:
{
"isValid": false,
"id": {
"isValid": false,
"id": 1,
"status": 1,
"consentConfirmations": [
{
"hasAcknowledged": false,
"text": "Display text 1"
},
{
"hasAcknowledged": false,
"text": "Display text 2"
},
{
"hasAcknowledged": false,
"text": "Display text 3"
}
],
"displayName": "Electronic Consent",
"footerText": "Awesome footer text",
"ordinalPosition": 0,
"formComponentType": "consent",
"text": "Display text"
},
"status": -1,
"consentConfirmations": []
}
This appears to be a very basic use case that I'm attempting. I've seen it in a number of examples but for some reason it does not work for me.
Angular version: 7.2.7
Akita version: 3.2.0
Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: 10.15.3
- Platform: Windows
What should the status be after the update?
@NetanelBasal I'm not sure if this is a bug or something that needs to be documented better.
I haven't wired up my HTTP service yet so in one of my services I hand back an array of IForm objects where each object is actually an instance of a class. I made the classes as a way to help ease the burden of making a bunch of hardcoded data objects. That way the constructors could take some of the initialization burden off of me. :)
It seems like line 201 is calling the constructor of the object to make the new state object. Is that a correct reading? If that is the case the first parameter of the constructor for my class is the id field. When I saw this it hit me why a copy of the object was getting shoved in there.
I made all the constructors parameter-less in an attempt to solve the issue. This didn't work as well. It just set the state to a default object instance. It then occurred to me that since the code is passing in the new state to the constructor that it is essentially expecting any object to be a copy constructor. Once I did this it appears to work correctly. Is that a correct assumption?
If classes are expected to have a copy constructor that is fine. It would be nice to have this documented or called out.
When working with classes, you must use one object parameter in the constructor. I also not recommend using classes. Read the section about it in the docs:
I have added a paragraph about the class constructor. Thanks.
@NetanelBasal, did that page get added before or after I logged this ticket? I closed all the tabs with the docs that I was looking at when working the issue so I don't know if I had v3.0.0 selected or v3.2.0. I feel silly if that was there the entire time...
Thanks again!
It was in earlier versions, and now I added it back. Don't feel silly :)
Most helpful comment
It was in earlier versions, and now I added it back. Don't feel silly :)