These are chat archives for canjs/canjs

7th
Apr 2017
Szabolcs Schmidt
@sszabolcs
Apr 07 2017 11:17

Hi!

I've run into something I cannot decide whether it is a bug or not?!
I'm using CanJS 3.
If I give a custom id property to my can.Model and issue a findOne() command for the second time - to reload the model - can-connect/can/model/model.js does not find the id value in the response data and so it does not refresh the model in the store. model.js@1.3.8 in line 41:

var idProp = inst.constructor.id || 'id';

results 'id' as idProp value but should result the custom id property name. If I rewrite this line to this:

var idProp = inst.constructor.id || this.idProp || 'id';

i.e. add 'this.idProp' to the line then idProp gets the correct value, my custom id property name and the model in the store refreshes.

I would like to ask if my solution were right? Could you give me a better one?

Here is a fiddle which works, it uses 'stock' id property, the model is refreshed after the second findOne call:
https://jsfiddle.net/9uq9s7kp/

And here is a fiddle with custom id prop value which does not refresh the model after the second findOne call:
https://jsfiddle.net/fxez1erz/

In the example after clicking the Save link the changeCount in the model should increase because it is increased on the 'server' side.

Thanks!

Nico R.
@nriesco
Apr 07 2017 19:58
I’m moving from donejs 0.9 to 1.0 and import route from "can/route/“; won’t work now. What is the new way of imporing route?
Matthew Phillips
@matthewp
Apr 07 2017 20:00
can-route
Nico R.
@nriesco
Apr 07 2017 20:37
great!
route is still causing me some trouble
I guess a lot changed
but I get a lot of TypeError: Cannot define property:page, object is not extensible. (page is the first ‘segment’ of my route)
Nico R.
@nriesco
Apr 07 2017 20:42
I have something like this:
route('{page}', { section: null, subSection: null });
route('{page}/{section}', { page: null, section: null, subSection: null });
route('{page}/{section}/{subSection}', { page: null, section: null, subSection: null });
it used to work
using :section notation
Nico R.
@nriesco
Apr 07 2017 20:50
mmm
this seems to work
route('{page}');
but this one not:
route('{page}');
route('{page}/{section}', {section: null});
I’m not even reading from any of those, just trying to render http://localhost:8080/one/two
and that triggers TypeError: Cannot define property:section, object is not extensible.
Nico R.
@nriesco
Apr 07 2017 20:55
I copied from place-my-order this:
route('{page}', { page: 'home' });
route('{page}/{slug}', { slug: null });
route('{page}/{slug}/{action}', { slug: null, action: null });
and didn’t work either
TypeError: Cannot define property:slug, object is not extensible.
Chasen Le Hara
@chasenlehara
Apr 07 2017 21:12
@sszabolcs That seems like a reasonable change, would you mind filing an issue here please? https://github.com/canjs/can-connect/issues
Nico R.
@nriesco
Apr 07 2017 21:12
fixed: I had to explicitly declare the variables in the defineMap