These are chat archives for canjs/canjs

29th
Jun 2016
Jeremy Miller
@jjm340
Jun 29 2016 01:41
Is having a property on the view model with a getter and a can.compute different?
Jeremy Miller
@jjm340
Jun 29 2016 02:03
Excuse my ignore, but I'm the newbiest of newbies when it comes to canJs
qantourisc
@qantourisc
Jun 29 2016 05:03
@jjm340 I am also green, so witch getter are you referring to ?
JigneshVasoya3292
@JigneshVasoya3292
Jun 29 2016 09:17
Hi ALl,
i'm not able to run 'geunt test' as there is some issue with installing the depedencies
can anyone help me?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jun 29 2016 09:18
@JigneshVasoya3292 can you give more information?
JigneshVasoya3292
@JigneshVasoya3292
Jun 29 2016 09:18
It fails to find 'zepto' under canjs/bower_components
you want to me put complete logs for 'npm install'
I see it doesn't install all dependencies
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jun 29 2016 09:19
you should install zepto
JigneshVasoya3292
@JigneshVasoya3292
Jun 29 2016 09:20
Yes, npm install on canjs folder should install all dpenedecies, I assume
Or should I install it seperately?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jun 29 2016 09:23
yes install it seperately
JigneshVasoya3292
@JigneshVasoya3292
Jun 29 2016 09:23
sure, let me try that
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jun 29 2016 09:24
I dont know if zepto has official npm package
JigneshVasoya3292
@JigneshVasoya3292
Jun 29 2016 10:49
It's filing to install docco
does it require some VS compiler as prerequisites?
or some VS installed on windows machine?
qantourisc
@qantourisc
Jun 29 2016 12:04
Can't find the isdefered thingy for rendering with stache, i'm sure it's there, but I cannot find it atm.
Ok I should type here more often, just found it again #if promise.isPending()
Kevin Phillips
@phillipskevin
Jun 29 2016 14:18
@jjm340 can.compute is used under the hood with the other observable types (can.Map, can.List). So, putting a property on a viewModel with a getter is similar to using a compute directly.
hope that answers your question
qantourisc
@qantourisc
Jun 29 2016 14:38
What is the best way to prevent can.Map.bind to launch multiple ajax request ? (Example: when clearing a map representing a filter for a table). It will result in multiple change events to be launched (1 for each paramater) this is kind of tricky.
Kevin Phillips
@phillipskevin
Jun 29 2016 14:39
how are you clearing the map?
https://canjs.com/docs/can.batch.html is probably what you’re looking for
qantourisc
@qantourisc
Jun 29 2016 14:40
Atm poorly (1 by 1) just done a small test before this question, to see if amap.attr({}) would yield different results, but didn't.
qantourisc
@qantourisc
Jun 29 2016 14:45
@phillipskevin Atm I cannot even think of a solution: on one hand you wish to be able to listen to single keys and their change. On the other hand you want to receive ev,attr,how,newVal,oldVal where attr is bascially a list of changed properties
the only other solution, I see atm is making a custom event and trigger that, but then it becomes manual labour again
Kevin Phillips
@phillipskevin
Jun 29 2016 14:46
I’m not sure what you mean I guess
how are you listening to the events?
qantourisc @qantourisc looks for the fillde/testcase thing
Kevin Phillips
@phillipskevin
Jun 29 2016 14:46
there is a change event that will trigger whenever any property on the map changes
qantourisc
@qantourisc
Jun 29 2016 14:46
ow it's linked in topic swat, let me make a testcase
@phillipskevin http://jsbin.com/nupayulipu/edit?js,console <= there we go
As you see (and kind of expect) it fires 2 times
what does one do if you only want it to fire once
qantourisc
@qantourisc
Jun 29 2016 14:55
I suppose in this case I could flip a bit to prevent certain triggers from running
Kevin Phillips
@phillipskevin
Jun 29 2016 15:01
so, doing it that way… with attr({}) causes the events to be batched, which is good
if you change the console to console.log(attr+how+ov+nv+'|'+ev.batchNum); you’ll see they have the same batchNum

whereas

amap.attr({a:1});
amap.attr({b:1});

would be two separate batches

what that means is that the change event won’t be triggered until all of the changes have happened
qantourisc
@qantourisc
Jun 29 2016 15:04
ow so you want to check the bactch-number before triggering
sounds saner
Kevin Phillips
@phillipskevin
Jun 29 2016 15:04
if you log console.log(amap.attr()); in your change handler you’ll see that it is {a:1, b:1} both times the change handler is triggered
qantourisc
@qantourisc
Jun 29 2016 15:05
I assumed as mutch :)
Kevin Phillips
@phillipskevin
Jun 29 2016 15:05
you could do that… but there would be a delay
qantourisc
@qantourisc
Jun 29 2016 15:05
hold on i'll update the example
Kevin Phillips
@phillipskevin
Jun 29 2016 15:05
I would try to figure out if there’s a single event that you can listen to
qantourisc
@qantourisc
Jun 29 2016 15:06
not in this case
qantourisc
@qantourisc
Jun 29 2016 15:13
@phillipskevin Something along the lines of the monstrocity http://jsbin.com/nupayulipu/edit?html,js,console,output
Kevin Phillips
@phillipskevin
Jun 29 2016 15:15
yeah, I think there must be a better way to do it but don’t have a suggestion for you off the top of my head
qantourisc
@qantourisc
Jun 29 2016 15:16
@phillipskevin a decorator, (a function returning a wrapped function, containing this code)
Kevin Phillips
@phillipskevin
Jun 29 2016 15:18
yeah, I guess that’s almost exaclty the code given in the docs
qantourisc
@qantourisc
Jun 29 2016 15:19
ow indeed, I missed that, canjs documentation is so dence :/
Kevin Phillips
@phillipskevin
Jun 29 2016 15:28
a lot of work is being done on the docs for 3.0
qantourisc
@qantourisc
Jun 29 2016 15:29
dence just means: skim less diagonal, more horizontal, it's MY fault, not the docs
Kevin Phillips
@phillipskevin
Jun 29 2016 15:29
I missed it too and I’ve read it before
qantourisc
@qantourisc
Jun 29 2016 15:37
Here is my solution
 can.Map.prototype.binder = function(attr,how,func){
    var _attr = new Set( attr.split(" "));
    var _how  = new Set(  how.split(" "));
    var batchNum=undefined;
    return this.bind("change",
        function(ev,attr,how,newVal,oldVal){
            if (
                   (  _how.has("*") ||  _how.has(how ) )
                && ( _attr.has("*") || _attr.has(attr) )
                && ( !ev.batchNum   || batchNum != ev.batchNum )
            ){
                batchNum = ev.batchNum;
                return func(ev,attr,how,newVal,oldVal);
            }
        }
    );
}
Jeremy Miller
@jjm340
Jun 29 2016 15:52
@phillipskevin That answers my question, thanks!
Kevin Phillips
@phillipskevin
Jun 29 2016 15:53
no problem
qantourisc
@qantourisc
Jun 29 2016 16:12
Ok interesting bug/artefact: {{#switch choice}} {{#case "a"}} <comp-a> {{/case}} {{#default}} {{choice}} {{/default}} {{/switch}} Will create comp-a twice, because it re-render the page twice: 1 triggers on the switch
the other trggers on the {{choice}} bind
qantourisc
@qantourisc
Jun 29 2016 20:33
If I wish to have a variable available from window, how should I do this ? Ideally I would make a helper, but i'm not entirly sure how. I looked at the definition of #if helper, but it leaves me with some questions. I suppose I should just copy #if and see if it works ?
Kevin Phillips
@phillipskevin
Jun 29 2016 20:35
you should probably just store the variable on a viewModel somewhere
qantourisc
@qantourisc
Jun 29 2016 20:40
That could work, but I realize now that I want the control the else part globally
actually, no bad idea, i'll just make a tiny helper for the else par
thanks, your suggestion should work.
qantourisc
@qantourisc
Jun 29 2016 21:15
Thinking about it, for the sanest, use a helper would be best, but I can't figure out atm how to rerender/bind it to changes.
(and i'm not working on an element i'm working on an options.fn section or alike)
qantourisc
@qantourisc
Jun 29 2016 21:25
OMG, it's smart, it figures out what you use !
rats, but returning a simple DOM element is not enough to recrusivley trigger the stache-comp instancing