These are chat archives for canjs/canjs

20th
Jul 2017
Viktor Busko
@Lighttree
Jul 20 2017 08:42

Guys, what is the purpose of set / algebra in can.js 3:
https://canjs.com/doc/can-set.html

It seems like this is used widely in examples for models and people use it. But to be honest I don't understand the use-case. Is this something that I must use ?

Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:43
it maps values
Viktor Busko
@Lighttree
Jul 20 2017 08:43
mmm...
Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:44
as the name says set algebra
tells what to set on the viewmodel
Viktor Busko
@Lighttree
Jul 20 2017 08:44
import DefineMap from 'can-define/map/map';
import DefineList from 'can-define/list/list';
import set from 'can-set';
import superMap from 'can-connect/can/super-map/super-map';
import loader from '@loader';

const Example = DefineMap.extend({
    seal: false
}, {
    id: 'any'
});

const algebra = new set.Algebra(
    set.props.id('id')
);

Example.List = DefineList.extend({
    '#': Example
});

Example.connection = superMap({
    url: loader.serviceBaseURL + '/example',
    Map: Example,
    List: Example.List,
    name: 'example',
    algebra
});

export default Example;
Why in this example id in set ? :)
what if I skip it ?
Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:45
then you probally get problems
Viktor Busko
@Lighttree
Jul 20 2017 08:45
:D
Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:45
the viewModel needs a id prob
to create lists and that
Viktor Busko
@Lighttree
Jul 20 2017 08:45
you mean it sets response -> viewModel
Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:45
and track its state
Viktor Busko
@Lighttree
Jul 20 2017 08:45
so it says like "take id from response and set it to id in vm" ?
Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:45
so the algebra tells the viewModel what property it should use as uniq id
to identify instances
Viktor Busko
@Lighttree
Jul 20 2017 08:45
mmm...
Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:46
yes it is like that
if you for example have in some cases _id as id Prop
or lets say you return books
they got a isbn :)
then the isbn is a good id value or if your using anything else
you can use anything as id as long as it is uniq
if your not working with lists
then this is not needed i think but justin is the only one who knows that exactly
:D
He did the main concepts of that i think
maybe this will help you
Viktor Busko
@Lighttree
Jul 20 2017 08:49

So in canjs 2 we had this to set what field is ID:

can.Model.extend('Example', {
    id: `_id`,
    findAll: 'url',
    create: 'url'
}, {});

And in canjs 3 in this case we need to set algebra ?

Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:49
right
and it can do even more
Viktor Busko
@Lighttree
Jul 20 2017 08:49
but I shouldn't list all my props in algebra ?
Frank Lemanschik
@frank-dspeed
Jul 20 2017 08:50
shouldn't is the wrong word
depends on what you need
Viktor Busko
@Lighttree
Jul 20 2017 08:52
ok thanks will use it for id only for now :)
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 20 2017 09:36
@Lighttree it can be used to configure how can-connect will talk with the server API
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 20 2017 09:43
@Lighttree the id prop is just and example I think it accepts id prop by default but if it changes for example instead of id you can have uuid or _id in that case you should specified in the set and also if you have for example entry model in blog platform which can have published prop and the server returns 0 for unpublished and 1 for published you can converted with can-setlike this set.props.boolean("published")
Viktor Busko
@Lighttree
Jul 20 2017 09:44
ok I think I got the idea
Kevin Phillips
@phillipskevin
Jul 20 2017 14:12
the set algebra is used mainly for real-time and fall-through caching
so that can-connect can understand when an update is made to an item in a list
or whether one list is a subset/superset of another list
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:14
kevin i was thinking about possible api's to redesign that how does that sound couldn't each behavier maybe be a single module with its own config and algebra where we replace algebra with logical configuration settings per behavier?
Kevin Phillips
@phillipskevin
Jul 20 2017 14:15
there is an Epic for revisiting can-set to make it easier to understand: canjs/can-set#54
if you have ideas, feel free to post them there
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:15
good idea thanks for the tip
where is can-set exactly used at present?
in can-connect as dependency right?
Kevin Phillips
@phillipskevin
Jul 20 2017 14:16
you can pass a set algebra to can-connect
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:16
or only in algebra so that we only use it in the algebra prop of can-connect ?
yes ok
Kevin Phillips
@phillipskevin
Jul 20 2017 14:16
superMap, etc
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:17
ok right can-set == algebra
i ask because i think maybe we should refactor or revisiting can-connect also
:D
Kevin Phillips
@phillipskevin
Jul 20 2017 14:18
yeah, we've talked about this
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:18
then we can eliminate the order problems with behaviers and all that
where do you talk about that?
Kevin Phillips
@phillipskevin
Jul 20 2017 14:18
there's an epic for this also: canjs/can-connect#288
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:18
in canjs/canjs =
hmmm ok so i need to reference the issues thanks a lot
Kevin Phillips
@phillipskevin
Jul 20 2017 14:19
we've talked about the work @nlundquist has been doing on contributor's meetings
and I'm sure we'll talk about it again at upcoming meetings
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:19
yes i heard that from nils
but i want to present something
Kevin Phillips
@phillipskevin
Jul 20 2017 14:19
ok
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:19
but i need 2 more weeks
i think i got it done to make a stream version of it
Kevin Phillips
@phillipskevin
Jul 20 2017 14:19
nice
event streams you mean, right?
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:20
yes simple.map().reduce() able streams
Kevin Phillips
@phillipskevin
Jul 20 2017 14:20
cool
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:20
using most the most fast lib for streams at present
so we can chain behaviers
and have a fixed order
Kevin Phillips
@phillipskevin
Jul 20 2017 14:20
:thumbsup:
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:22
who would i need to msg to get invite links for the google hangout
chasen?
Kevin Phillips
@phillipskevin
Jul 20 2017 14:22
@chasenlehara
yeah
Frank Lemanschik
@frank-dspeed
Jul 20 2017 14:23
perfect