These are chat archives for canjs/canjs

7th
Aug 2018
Kalaikaran K
@kalaikaran
Aug 07 2018 00:57
hi Guys I having problems with "helpers" can someone help me with an example
Also how can i check truthy of two expression in statche ?
Justin Meyer
@justinbmeyer
Aug 07 2018 01:19
@kalaikaran like {{#if( something ) }} ?
it sounds like you want an and
there's an issue about creating and and or helpers
but a simple version would look like:
stache.addHelper("and", function(v1, v2){
  return v1 && v2
});
you should be able to use that like
{{# if( and(foo, bar) ) }}
Dovid Bleier
@dbleier
Aug 07 2018 12:08
@phillipskevin Test 1, I already tried and the data DID show up in the input fields
Test 2, what should be in the new-component? I assume it needs a can-import even though you didn't put it in the example
Dovid Bleier
@dbleier
Aug 07 2018 12:20
ok, here is what I did - created a new component:
<can-component tag="new-comp">
    <template>
        <input value:bind="markup">
        <input value:bind="externals" >
        <input value:bind="code" >
    </template>
    <script type="view-model">
        import DefineMap from 'can-define/map/';
        export default DefineMap.extend({
            html: {
                type: '*',
                set(nv) {
                    console.log('*********** HTML: ' + nv);
                    return nv;
                }
            },
            markup: {
                type: 'string',
                set(nv) {
                    console.log('*********** MARKUP: ' + nv);
                    return nv;
                }
            },
            code: 'string',
            externals: '*',
        });
    </script>
</can-component>
put in the parent stache
    <can-import  from="./new-comp.component" />
    {{debugger}}
    <new-comp markup:from="html.markup" externals:from="html.externals" 
        code:from="html.code"></new-comp>
it debugger, shows values are in scope
but the inputs are empty and the setter is being passed empty string :
:frowning:
Gregg Roemhildt
@roemhildtg
Aug 07 2018 12:56
Heyall, just an fyi, I'm getting extra console.logs in production canjs installs: https://github.com/canjs/can-attribute-observable/blob/master/can-attribute-observable.js#L96
Kevin Phillips
@phillipskevin
Aug 07 2018 13:16
thanks @roemhildtg, we'll get a fix out
Gregg Roemhildt
@roemhildtg
Aug 07 2018 13:18
np
Kevin Phillips
@phillipskevin
Aug 07 2018 13:43
@roemhildtg I published a patch of can-attribute-observable
to remove that
Gregg Roemhildt
@roemhildtg
Aug 07 2018 13:44
Sounds good :thumbsup:
Dovid Bleier
@dbleier
Aug 07 2018 14:02
@phillipskevin thanks for your continued help. Any suggestions at this point?
Kevin Phillips
@phillipskevin
Aug 07 2018 14:03
yeah, sorry, I haven't forgotten about your issue... just trying to figure out what to suggest next
Dovid Bleier
@dbleier
Aug 07 2018 14:03
thanks
Kevin Phillips
@phillipskevin
Aug 07 2018 14:03
so when you say "values are in scope", did you check the exact values? like options.scope.get("html.markup");
Dovid Bleier
@dbleier
Aug 07 2018 14:03
yes
Kevin Phillips
@phillipskevin
Aug 07 2018 14:04
so when the setter gets called... can you walk up the call stack to make sure it's triggered by can-stache-bindings?
Dovid Bleier
@dbleier
Aug 07 2018 14:08
I started walking up the stack and it was "" until I got a bit lost
which method should I be looking in: initialiveValues, completeBinding, makeDataBinding, data
getValue(childObservable) in initiateValues returns ""
Dovid Bleier
@dbleier
Aug 07 2018 14:14
seems that the setter is getting called when trying to bind markup to the value:bind in the input in the component itself, or actually perhaps the reverse
I switched value:bind to value:from in the input in the component, and lo and behold, the setter is not getting called
so it was being called from the child to the parent due to the 2-way binding
but not from the components parent, which is were we started
Kevin Phillips
@phillipskevin
Aug 07 2018 14:17
ok
that makes more sense
there is a parentToChild function in can-stache-bindings
it should return an updateChild function
I would put a breakpoint in updateChild
Dovid Bleier
@dbleier
Aug 07 2018 14:21
I put a bp in makeDataBindings which calls parentToChild
it only stops there when trying to make the bindings to the inputs in the component, it never fires for the component itself
Kevin Phillips
@phillipskevin
Aug 07 2018 14:27
very strange... just to be sure, can you import can-stache-bindings in your component
<can-import from="can-stache-bindings" /> should work I think
Dovid Bleier
@dbleier
Aug 07 2018 14:34
in the parent template or the component's template?
Kevin Phillips
@phillipskevin
Aug 07 2018 14:34
the parent template
Dovid Bleier
@dbleier
Aug 07 2018 14:35
tried it, didn't see any errors
Kevin Phillips
@phillipskevin
Aug 07 2018 14:36
but the component still doesn't work?
Dovid Bleier
@dbleier
Aug 07 2018 14:36
nope
the component loads, but without the data
I even tried adding to the parent components define obj
markup: {
            type: 'string',
            value: 'markup'
        }
and the markup:from="markup" in the template, and still nothing
Kevin Phillips
@phillipskevin
Aug 07 2018 14:53
so does behaviors.data not get called at all for that element?
Dovid Bleier
@dbleier
Aug 07 2018 17:07
I guess not, but how do I check that for sure?
Kevin Phillips
@phillipskevin
Aug 07 2018 17:34
put a breakpoint in that function and check for el.tagName === "NEW-COMP"