These are chat archives for canjs/canjs

31st
May 2016
Andrei Balmus
@abalmush
May 31 2016 09:52

guys how to use https://github.com/canjs/can-connect in case I have cart data like:

{
      cartId: “000001”,
      entries: [{…}, {…}]
      …
}

The entries is a list but it’s inside object how to say can-connect that data is a Map with entries inside it. I dont know if I explained it correctly.

Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 09:53
@abalmush in the Model you can add the type of entries
Andrei Balmus
@abalmush
May 31 2016 10:18
Thank you very much! @cherifGsoul
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 10:18
np
Andrei Balmus
@abalmush
May 31 2016 10:38
@cherifGsoul could you please take a look at this: http://jsbin.com/tagukeqaxe/1/edit?js,console trying to get it to work, and no result :( this is the first time wen I’m using can-connect, before I used can.Model
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 10:41
entries: { Type: CartEntry.List }
Andrei Balmus
@abalmush
May 31 2016 10:48
Promise.reject is not a constructor - do I need to include Promise pollyfil or something?
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 10:48
I see that in the jsbin im checking
Andrei Balmus
@abalmush
May 31 2016 10:49
oh ok thanks, I’ll try to use it outside jsbin and see if it works, Thank you very much!
for your help
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 10:49
np
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:09
@abalmush the fixture definition is the problem you should return a list
Andrei Balmus
@abalmush
May 31 2016 11:15
How about if the service returns json like:
{"basket":{"code":"00000001","net":false,"totalPriceWithTax":{"currencyIso":"GBP","value":1550.0,"priceType":"BUY","formattedValue":"£1,550.00","minQuantity":null,"maxQuantity":null},"totalPrice":{"currencyIso":"GBP","value":1550.0,”
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:15
I think you should have your own behavior to parse the response
Andrei Balmus
@abalmush
May 31 2016 11:16
oh, i undertsand I need to create new behavior, ok I’ll take a look how to do that
thanks
BTW i tried the code from JSBIN and I’m getting this error:
system.js:4 Uncaught (in promise) Error: TypeError: behaviors.map is not a function
but behavor has Map property
capital case
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:17
if you use the superMap, it should have the all required behaviors
Andrei Balmus
@abalmush
May 31 2016 11:19
that’s interestion because if I use it I’m getting: Error: TypeError: connect.superMap is not a function(…)
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:19
clone this http://jsbin.com/nazewa/edit?html,js and make sure it works :)
Andrei Balmus
@abalmush
May 31 2016 11:20
ok
same problem: Error: TypeError: connect.superMap is not a function(…) looks like it is not included in my project, I installed it using npm
I will play with it, this is the issue with my packages
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:23
ok
Andrei Balmus
@abalmush
May 31 2016 11:23
thanks again for you help @cherifGsoul
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:24
anyways if you should have related maps just specify the type
Andrei Balmus
@abalmush
May 31 2016 11:24
ok
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:24
you are welcome
Andrei Balmus
@abalmush
May 31 2016 11:31
oh ) instead can-connect.js I should include all.js so main entry point for jspm will be all.js :)
Mohamed Cherif Bouchelaghem
@cherifGsoul
May 31 2016 11:32
ok nice
Andrei Balmus
@abalmush
May 31 2016 11:32
thats why superMap is not defined ;)
Andrei Balmus
@abalmush
May 31 2016 11:54

The all.js in cjs folder of the can-connect module looks like this:

var connect = window.connect = require('./can-connect.js');
connect.cacheRequests = require('./cache-requests/cache-requests.js');
connect.constructor = require('./constructor/constructor.js');
connect.constructorCallbacksOnce = require('./constructor/callbacks-once/callbacks-once.js');
connect.constructorStore = require('./constructor/store/store.js');
connect.dataCallbacks = require('./data/callbacks/callbacks.js');
connect.dataCallbacksCache = require('./data/callbacks-cache/callbacks-cache.js');
connect.dataCombineRequests = require('./data/combine-requests/combine-requests.js');
connect.dataInlineCache = require('./data/inline-cache/inline-cache.js');
connect.dataLocalStorageCache = require('./data/localstorage-cache/localstorage-cache.js');
connect.dataMemoryCache = require('./data/memory-cache/memory-cache.js');
connect.dataParse = require('./data/parse/parse.js');
connect.dataUrl = require('./data/url/url.js');
connect.fallThroughCache = require('./fall-through-cache/fall-through-cache.js');
connect.realTime = require('./real-time/real-time.js');
connect.fixture = require('can-fixture');
connect.Model = require('./can/model/model.js');
connect.superMap = require('./can/super-map/super-map.js');
require('./can/tag/tag.js’);

there is no export I’m not sure if it work with JSPM and SystemJS :(

Joel Kuzmarski
@leoj3n
May 31 2016 18:52
This message was deleted
Mason Shin
@minsooshin
May 31 2016 19:55
@Macrofig yes, I have resolved the issue with can-validate. I think old bootstrap has the issue with contains prototype of array.
new bootstrap doesn’t have the issue since it changed to regex test :)
Chris
@chrischrischris
May 31 2016 21:12
Is there a way to inject list contents into a component when iterating over the list - at the moment I can make it work with the item binding, but would rather not have to preface it:
{{#myList}}
<mycomponent {item}="."></mycomponent>
{{/myList}}
Kevin Phillips
@phillipskevin
May 31 2016 21:13
not sure what you mean by preface
Thomas Sieverding
@Bajix
May 31 2016 21:14
I think he’s saying he wants the content context to become the component’s view model
Chris
@chrischrischris
May 31 2016 21:14
every binding inside of mycomponent needs to have a value of {{item.value}}
I guess I could use {{#with item}} ... {{/with}}
@Bajix yes that's what I'm trying to do.
Thomas Sieverding
@Bajix
May 31 2016 21:18
Yea, I’ve been tempted to do that before
You should avoid doing that though
Chris
@chrischrischris
May 31 2016 21:18
what did you end up doing?
Thomas Sieverding
@Bajix
May 31 2016 21:19
{{#users}}
  <avatar {user}="."></avatar>
{{/users}}
You should always pass it as a property on the VM
That way, your viewModel can have other properties without introducing side-effects
Chris
@chrischrischris
May 31 2016 21:21
ok thanks, I'll just use that way then.
Thomas Sieverding
@Bajix
May 31 2016 21:22
Also, there are other properties used internally on the VM
Such as root
Chris
@chrischrischris
May 31 2016 21:22
just to double check - the component does not have access to the parent context right?
Thomas Sieverding
@Bajix
May 31 2016 21:23
it does
There are multiple viewModel signatures
You could pass in a function with the params attr, parentVM, and read the parent context that way
Joel Kuzmarski
@leoj3n
May 31 2016 21:24
I'm trying to understand the parentScope {can.view.viewModel} parameter of the viewModel function in a can.Component. The docs say parentScope is "The viewModel the custom tag was found within." Can someone explain what parentScope points to for the example: <my-element title='name'></my-element>?
Thomas Sieverding
@Bajix
May 31 2016 21:24
It would still need to return a can.Map instance
Chris
@chrischrischris
May 31 2016 21:25
yes ok I've used that, but to map component template values to the parentscope would require explicit mapping in the viewmodel
Kevin Phillips
@phillipskevin
May 31 2016 21:26
@leoj3n it’s the scope outside of that… it depends on what template <my-element title='name'></my-element> is found in
the parentScope of the <home-page /> component is can.route
Joel Kuzmarski
@leoj3n
May 31 2016 22:14
@phillipskevin can.route is a function; Why is it passed as the data with which to render the app-template view? I can see that <app-template /> contains <home-page />.
Joel Kuzmarski
@leoj3n
May 31 2016 22:26
@phillipskevin Nevermind, that was a niave statement. I see now it holds other properties like can.route.data.
Kevin Phillips
@phillipskevin
May 31 2016 22:26
ok, I wasn’t really sure to be honest
Joel Kuzmarski
@leoj3n
May 31 2016 23:07
Does can.route get special treatment when passed as data to can.view? http://jsbin.com/zifacaluyo/edit?html,js