These are chat archives for canjs/canjs

31st
Oct 2018
Viktor Busko
@Lighttree
Oct 31 2018 10:34
Guys is there big difference between such getters in VM ?
get someProp() {
        return 'something';
},

// VS

someProp: {
    get() {
         return 'something';
    }
}
Maybe some preferences when to use
kostya.aderiho
@kaderiho
Oct 31 2018 15:27

Hi guys, is there any way to save DefineList data on the server using PUT request?

For instance:

const Todo = DefineMap.extend({ ... some properties ... });

Todo.List = DefineList.extend({ "#": Todo });

let TodosList = new Todo.List([ ...several items there... ]);

// send PUT request here with TodoList inside of the body

Thank you in advance

Matthew Phillips
@matthewp
Oct 31 2018 15:28
are you using can-rest-model?
kostya.aderiho
@kaderiho
Oct 31 2018 15:32
So I'm using canjs v3 and can-connect as a middleware for data layer
Matthew Phillips
@matthewp
Oct 31 2018 15:33
ok cool
so when you call .save() what happens?
Oh, do you mean you need it to use PUT even for new items?
kostya.aderiho
@kaderiho
Oct 31 2018 15:35
I need to use PUT for already retrieved items by .getList method. If I understand correctly I can not do TodoList.save() because .save works for one instance only
Matthew Phillips
@matthewp
Oct 31 2018 15:38
why can't you do todoList.forEach(todo => todo.save()) ?
kostya.aderiho
@kaderiho
Oct 31 2018 15:39
It's an option but it will cause a lot of requests in case of large list :)
Matthew Phillips
@matthewp
Oct 31 2018 15:41
There's the combine-requests behavior that combines requests together
not sure if it works for saving though...
pinging @justinbmeyer in case he has a solution for this
I think combine-requests only works for getting lists
Justin Meyer
@justinbmeyer
Oct 31 2018 15:44
I think someone asked this and posted solution in the forums
kostya.aderiho
@kaderiho
Oct 31 2018 15:53
Seems that combineRequests works only for get (getListData) requests (according to the documentation), is it correct guys or not?
Frank Lemanschik
@frank-dspeed
Oct 31 2018 15:56
i would say
1 reqest per save is total ok
if you need to save more data then simply do a custom batch via a endpoint that supports that
Matthew Phillips
@matthewp
Oct 31 2018 15:57
@kaderiho yep, that is correct
Frank Lemanschik
@frank-dspeed
Oct 31 2018 15:57
but out of my view you should save the item on creation
there is no case where you save more then 1 item at time and if you batch edit items via your interface directly
you end up in 1 request per processed item
thats total ok
else simply send item ids and changes to the backend and process them there
a batch endpoint would be a simple endpoint that accepts json lists
then you do getList and post that json to that endpoint
your done
the endpoint then takes that json list and does the for each serverside
I think that's the forum post @justinbmeyer is talking about
the linked to jsbin shows an example that does bulk deletes
Frank Lemanschik
@frank-dspeed
Oct 31 2018 16:01
ya the question now is do you want to do bulk on the interface aka from the client side
or from the backend aka batch bulk enabled api endpoint
Justin Meyer
@justinbmeyer
Oct 31 2018 16:02
@jeroencornelissen I think I shared some code too
this is your code
it adds a destroyList method
that sends the json to a endpoint that does the foreach
:D
Justin Meyer
@justinbmeyer
Oct 31 2018 16:04
that's my code?
Frank Lemanschik
@frank-dspeed
Oct 31 2018 16:04
yes
Justin Meyer
@justinbmeyer
Oct 31 2018 16:04
I generally don't write code like that
Matthew Phillips
@matthewp
Oct 31 2018 16:04
it's from that forum post, not sure if you wrote it or @jeroencornelissen did
Frank Lemanschik
@frank-dspeed
Oct 31 2018 16:04

@justinbmeyer suggested this on the gitter channel:

I would put a destroyList or some method on your list that makes the requests
and then call destroyedInstance on each one (assuming can-connect)

I have tried that but couldn’t make it work. The items are updated when calling Item.Connection.destroyedInstance(item, {title: 'destroyed'});. The title changes to destroyed, but I expected them to get removed from the list.

See this fiddle 3:

ah ok
it was gregromhild
sorry
:D
readed it wrong i tought he copyed your text
Justin Meyer
@justinbmeyer
Oct 31 2018 16:05
I remember giving code IN gitter, I wish there was a link to the gitter thread
Frank Lemanschik
@frank-dspeed
Oct 31 2018 16:05
if you got gitter pro
you should be able to find it
do you got a pro account?
it has infinity history and search
as far as i remember
Justin Meyer
@justinbmeyer
Oct 31 2018 16:08
basically, the .save() on a list would need to update the instances correctly
there's a way to do that
Frank Lemanschik
@frank-dspeed
Oct 31 2018 16:08
dispatch
Justin Meyer
@justinbmeyer
Oct 31 2018 16:08
it's not dispatch
(though a dispatch happens)
I'd look it up but in the middle of something
Frank Lemanschik
@frank-dspeed
Oct 31 2018 16:09
i saw in some examples that there was custom dispatch on stuff like
can-define backup
thats why i got that idea
Justin Meyer
@justinbmeyer
Oct 31 2018 16:09
essentially you would need to re-create what the normal .save() does on every item in the list
Frank Lemanschik
@frank-dspeed
Oct 31 2018 16:09
thats correct
it will call some defineMap methods
maybe set ? update somestuff like that
i use that methods when i don't use can connect
to directly update instances
or save maybe as i remember uses the methods
added by can connect
!
this are the right api's i think to tigger updates
the crud methods
Mike 'mitch' Mitchel
@mikemitchel
Oct 31 2018 16:21
added the .sort method back to can-list 4.2.0
https://github.com/canjs/can-list/releases/tag/v4.2.0
kostya.aderiho
@kaderiho
Oct 31 2018 17:11
according to your comments @frank-dspeed @justinbmeyer I need to write custom implementation updateListData in order to send one PUT request with list inside of body?
Frank Lemanschik
@frank-dspeed
Oct 31 2018 18:41
right
@kaderiho
kostya.aderiho
@kaderiho
Oct 31 2018 19:48
okey, thanks everyone