Skip to content
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

StoreManager does not use the Identity from the item if it is different of "id" #122

Open
gtux opened this issue Jul 19, 2017 · 2 comments

Comments

@gtux
Copy link

gtux commented Jul 19, 2017

I want to use a Observable Cache of JsonRest and Memory store but with different identity, in my case "idPlanificacion", but the calendar behavior is wrong on create new items, it does not allows me to drag either.

My Code:

var id = 1,
        jsonStore = new JsonRest({target:"/planificaciones", idProperty: "idPlanificacion"}),
        cacher = new Memory({idProperty: "idPlanificacion"}),
        store = new Observable(new Cache(jsonStore, cacher));

var calendar = new Calendar({
        dateInterval: "week",
        columnViewProps: {
            timeSlotDuration: 60,
            minHours: 0,
            maxHours: 24,
            hourSize: 25
        },
        store: store,
        editable: true,
        createOnGridClick: true,
        createItemFunc: createItem,
        templateString: template
    }, "calendar-wrap");

After a few hours I found that it may because the StorageManager does not get the identity in some cases:

StorageManager Line 102

for(i=l-1; i>=0; i--){
    if(this.items[i].id === tempId){
        this.items[i] = newItem;
	break;
    }
}

then again in the line 117

if(this.items && this.items[newIndex] && this.items[newIndex].id !== newItem.id){
    l = this.items.length;
    for(i=l-1; i>=0; i--){
        if(this.items[i].id === newItem.id){
	    this.items.splice(i, 1);
	    break;
	}
    }
    this.items.splice(newIndex, 0, newItem);
}

The identity of items are evaluate directly for "id". And I think this is the bug because when I change the properties of my store, set the idProperty to "id" everything works fine again.

@damiengarbarino
Copy link
Owner

damiengarbarino commented Aug 31, 2017

I fear that it's not that simple: this.items and newItem are "renderItems" it means that they are objects that have all properties with property bindings resolved.
So the id will always be in id property on this object.
A first check is to make sure that in your create item function that you are not using "id" but "idPlanificacion"...

@gtux
Copy link
Author

gtux commented Oct 24, 2017

Hi, thanks for your help. Yes, I do set the idPlanificacion instead of id at first attempt, but as it did failed change to id again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants