can-connect
can-connect copied to clipboard
Error after deleting items: seems a problem witch cache
I'm having issues when deleting items, it looks like the cache is not being updated and generating an error in the browser.
Somehow it ends up trying to read the _id property of an undefined object so instance (the parameter) must be checked first instead of assuming is a valid object.
I thing you might fix this really fast.
It could be great that if you fix this you could also fix 0.5.0 (0.5.1?) so donejs works as well Thanks
https://github.com/canjs/can-connect/blob/9845c89bc5bd428051100a79dae5b683514aca08/base/base.js#L83
id: function(instance){
var ids = [],
algebra = this.algebra;
if(algebra && algebra.clauses && algebra.clauses.id) {
for(var prop in algebra.clauses.id) {
ids.push(instance[prop]);
}
}
if(this.idProp && !ids.length) {
ids.push(instance[this.idProp]);
}
if(!ids.length) {
ids.push(instance.id);
}
// Join with something unlikely to be matched.
// TODO: provide a way to supply join
return ids.length > 1 ? ids.join("@|@"): ids[0];
},
@nriesco could you somehow recreate this? I think something else must be going wrong if id is called without an instance.
I'll try to recreate it and send more information later but I think the sequence is:
1- create object 1 2- create object 2 3- delete object 2 4- delete object 1
All of this while running donejs develop
Sent from my iPhone
On Nov 25, 2016, at 5:07 PM, Justin Meyer [email protected] wrote:
@nriesco could you somehow recreate this? I think something else must be going wrong if id is called without an instance.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
@justinbmeyer It looks like this is the real sequence
OK
- Create n objects
- Reload page
- you can delete items or add new items
Not OK:
- Create n objects
- Don't reload the page
- Remove 2 of those recently inserted objects ==> At this point everything is ok
- Remove another one
- An error is triggered
So adding elements, without reloading and then deleting three of them causes this issue. It happens most of the time, it sometimes happens after removing the second item, so it might be related to the speed I do things.
After this issue, even if you reload you'll have another browser error (see below). If you delete localStorage everything goes back to normal (or reopen the incognito window) and no error will be triggered.
BTW: I use can-connect-feathers 1.2.0, no authentication and tried using rest and sockets
unhandledRejection.js:23
Potentially unhandled rejection [5] TypeError: Cannot read property 'reason' of undefined
at Map.errorDisplay (http://localdev.riescorp.com:8080/src/purchaseOrderDetails/purchaseOrderDetails.js!eval:55:32)
at Map.options.helpers.(anonymous function) (http://localdev.riescorp.com:8080/node_modules/can/component/component.js:195:18)
at can.Compute.<anonymous> (http://localdev.riescorp.com:8080/node_modules/can/view/stache/expression.js:343:18)
at ObservedInfo.getValueAndBind (http://localdev.riescorp.com:8080/node_modules/can/compute/get_value_and_bind.js:114:27)
at can.Compute._on (http://localdev.riescorp.com:8080/node_modules/can/compute/proto_compute.js:417:14)
at can.Compute.<anonymous> (http://localdev.riescorp.com:8080/node_modules/can/compute/proto_compute.js:266:9)
at can.Compute._bindsetup (http://localdev.riescorp.com:8080/node_modules/can/compute/get_value_and_bind.js:328:18)
at can.Compute.can.bindAndSetup [as bind] (http://localdev.riescorp.com:8080/node_modules/can/util/bind/bind.js:21:11)
at Text.branchRenderer (http://localdev.riescorp.com:8080/node_modules/can/view/stache/mustache_core.js:325:29)
at hydrateCallbacks (http://localdev.riescorp.com:8080/node_modules/can/view/target/target.js:225:40)(anonymous function) @ unhandledRejection.js:23report @ unhandledRejection.js:50flush @ unhandledRejection.js:72
@justinbmeyer I created some gists to show the model and viewmodel involved
https://gist.github.com/nriesco
https://gist.github.com/nriesco/8905f363d9913bb9243dbf23c2ff68cd https://gist.github.com/nriesco/b9b36d99d03d216867259185163e877e https://gist.github.com/nriesco/6c3f43deccf89f45c17a8c08d85a6725