Calling rejectChanges on a entity with collection of complexTypes doubles the complexTypes in collection

余生颓废 提交于 2019-12-23 05:15:38

问题


This may be something I am doing wrong, but I am having an issue that I believe is repeatable. It may be by design, but right now I can't figure out how to get around it.

I have an entity with a few complexType arrays on them. If I push a new complexType into the array, I see the correct number of objects in the collection. If I call rejectChanges on the parent entity, it removes the new complexType but then copies all of the objects in that array.

Sample metadata -

metadataStore.addEntityType({
    shortName: "Person",
    namespace: "MyNameSpace",
    dataProperties: {
        id: { dataType: "String", isPartOfKey: true },
        emails: { complexTypeName: "Email:#MyNameSpace", isScalar: false }
    }
});

metadataStore.addEntityType({
    shortName: "Email",
    namespace: "MyNameSpace",
    isComplexType: true,
    dataProperties: {
        id: { dataType: "String" },
        text: { dataType: "String" },
        preferred: { dataType: "Boolean" }
    }
});

Steps to reproduce -

  1. Create an entity
  2. Add two complex types of email
  3. Save all changes
  4. Add another complex type of email
  5. Call entityAspect.rejectChanges() on the parent entity
  6. Look at the number of emails in the array now

I assume on steps 1-3 this will still reproduce the issue, right now I am getting the entity and the complex types from the server so I am only doing steps 4-6.

Notes

I tried calling rejectChanges on the complexAspect instead but it doesn't exist.

I have a ko.computed on the list of emails to return the 'preferred' one that sets the others to false, don't know if this is contributing

I am sorting the list of emails in the DOM

Edit

Just found that the same thing occurs when deleting one of the complex types and cancelling that change.


回答1:


Sorry for taking so long on this one. It slipped... It is now in the current GitHub repo and will go out with the next release.




回答2:


I don't know if you got a response for your problem but here is mine!

Reason: There is a bug in breeze that causes this behavior. I am referring to breeze v1.4.11 (still present in 1.4.12)

Solution: This is my fix for the issue:

complexArrayMixin._rejectChanges = function() {
    if (!this._origValues) return;
    var that = this;
    this.forEach(function(co) {
        clearAspect(co, that);
    });
    this.length = 0;
    this._origValues.forEach(function(co) {
        that.push(co);
    });

    // mathieug: previous call already fills array with origValues
    //Array.prototype.push.apply(this, this._origValues);
};


来源:https://stackoverflow.com/questions/21490003/calling-rejectchanges-on-a-entity-with-collection-of-complextypes-doubles-the-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!