These are chat archives for canjs/canjs

6th
Jun 2017
Yeswanth Raghav T
@tyraghav
Jun 06 2017 12:28
What does this do in the controller JS file...??
this.options.myModel=new MyModelDisplay("#myModelDisplay", { 'sharedModel':this.options.userModel});
Can anyone please help...
Brad Momberger
@bmomberger-bitovi
Jun 06 2017 14:14
@tyraghav I can guess based on the arguments passed that MyModelDisplay is a can.Control subclass, and a new instance is being attached to an element with the id myModelDisplay, then a reference to that Control is attached to the options of this which is probably also a can.Control
Brad Momberger
@bmomberger-bitovi
Jun 06 2017 14:35
@gregorgodoy Sure. The relevant part of the documentation for what we're doing is in https://canjs.com/doc/can-connect.html#Overwritebehaviors but I'll give a more concrete example. Give me a few minutes while I spin up a Glitch.
Brad Momberger
@bmomberger-bitovi
Jun 06 2017 15:30
OK check this out: here's a regular can-connect doing all the superMap stuff, while also adding your behavior in at the end. https://glitch.com/edit/#!/can-connect-custom-behaviors?path=app.js:63:1
At the bottom you see two file instances created, one has the _new property and one doesn't. Click "Show Live" at the top and you'll see the fixtures log a create message and an update message
gregorgodoy
@gregorgodoy
Jun 06 2017 15:45
@bmomberger-bitovi AWESOME! :clap: :clap: :clap: Now i understand how behaviors works and what superMap does. I just was following the Place My Order Guide, without knowing what superMap does. Thanks again for the code example and the comments between them! Invaluable help!!
Pedro Mendes
@pmgmendes
Jun 06 2017 17:12
Hi all,
For a specific model layer I need to apply some transformation in the raw response retrieved from the server.
Because the request parameters must be available when doing the transformation the data callbacks seem to be the way to go because the got* methods provide both response and request parameters as arguments.
The problem here is that the gotInstanceData method is not paired with getData in the data/callbacks behavior. I've opened an canjs/can-connect#301 for this.
Meanwhile, is there any other interface beside getData that provides both response and request data? I want to avoid overwriting getData because I don't want to setup the request manually..
Thanks.
Brad Momberger
@bmomberger-bitovi
Jun 06 2017 17:23
You can use the getData() interface in a custom behavior that you inject, for example, in between data/parse and data/url. Just call baseConnection.getData() from within your own getData function, and put your custom behavior at the right point in the ordering.
This is similar to the demo I did for @gregorgodoy earlier, but you'd want to inject your behavior in the middle of the list instead of at the bottom.
As long as you're calling baseConnection.getData from your own getData, you don't have to do your own request setup. It will just pass through to data/url, or feathers, or whatever base you're using.
Nils Lundquist
@nlundquist
Jun 06 2017 18:04
@pmgmendes I've responded to your issue. In the meantime however the best approach would what @bmomberger-bitovi suggests - overwriting getData in a custom behavior, calling the overwritten implementation of getData within it, and then doing whatever transformation you need to do to the response returned from the base implementation
Ranjan Subbiah
@ranjanbuilds
Jun 06 2017 18:19

hi, I am doing some unit testing using sinon.js and it modifies the viewmodel with its stub and spy methods. We are using defineMap.extend({seal:true},{}) and are therefore getting the following error when using sinon:

Cannot define property handleSalePrice, object is not extensible

handleSalePrice is the function being stubbed. In our test file we are importing ViewModel and assigning it to vm variable const vm = new ViewModel(). I am wondering if there is a easy way to set seal:false when importing in test file.

Brad Momberger
@bmomberger-bitovi
Jun 06 2017 18:20
new (ViewModel.extend({ seal: false}, {})();
Though it may be much easier to stub and spy on ViewModel.prototype instead, if you don't need separate stubs for separate instances.
Ranjan Subbiah
@ranjanbuilds
Jun 06 2017 18:30
thanks very much Brad
Ranjan Subbiah
@ranjanbuilds
Jun 06 2017 18:39
@bmomberger-bitovi would you mind pointing me in the right direction re: stub and spy on ViewModel.prototype, not entirely sure what you mean
Note that this won't run in JSBin initially, because sinonjs.io is a gh-page and doesn't have the correct security certificate.
Load up https://sinonjs.org/releases/sinon-2.3.2.js in your browser and click through the security warnings. Then it will work for you
Ranjan Subbiah
@ranjanbuilds
Jun 06 2017 18:57
awesome, thank you, running into a meeting but will look when I get back
Pedro Mendes
@pmgmendes
Jun 06 2017 19:53
@bmomberger-bitovi Thanks for the feedback. I've added that custom behavior implementing getData method and placed it between data/parser and data/url. That getData method is only called when I move the custom behavior after data/url. Either way, @justinbmeyer just labeled the issue as bug so as suggested I'm gonna try to do a pull request.
@nlundquist Thanks for the help.