These are chat archives for canjs/canjs

24th
May 2018
Gregg Roemhildt
@roemhildtg
May 24 2018 13:01
Hey @chasenlehara, that fixed the can-debug. Gotta update the main to can-debug.js
Andrey Furs
@yganda
May 24 2018 14:15
Hi guys, could someone help me? I have code like this: Object.connection.createInstance(object).then((res) => { this.dispatch('event-name', res.id); }); and the problem is event didn't fire. But if i dispatch it after then, all works correctly. May be someone knows why it isn't work?
Julian
@pYr0x
May 24 2018 14:31
this is the context of the parent object... is that correct?
if you set a breakpoint into the callback get it hitted?
Andrey Furs
@yganda
May 24 2018 14:58
yea
Justin Meyer
@justinbmeyer
May 24 2018 16:02
@jeroencornelissen here's the shield working: http://jsbin.com/hunohu/edit?html,js,console,output
Nico R.
@nriesco
May 24 2018 16:19

I need to know if there is a more efficient way to do this in a stache file:

{{#if(condition1)}}
  <div class="container">
    <div class="container-element">
      ... some long complex code here like:
      {{element}}
    </div>
  </div>
{{else}}
  ... same complex code ...
  {{element}}
{{/if}}

I end up writing the same code twice, I guess there must be another way of not doing this
Any idea?

Julian
@pYr0x
May 24 2018 21:23
slots?
or partials
Nico R.
@nriesco
May 24 2018 21:30
Slots? I haven’t heard of that.. partials I’ve tried but didn’t work in the past
can I include a file like in EJS?
Nico R.
@nriesco
May 24 2018 21:35

for instance this example

Component.extend({
    tag : 'my-email',
    view : stache(
        '<can-slot name="subject" />' +
        '<p>My Email</p>' +
        '<can-slot name="body" />'
    )
});

var renderer = stache(
    '<my-email>' +
        '<can-template name="subject">' +
            '<h1>{{subject}}</h1>' +
        '</can-template>' +
        '<can-template name="body">' +
            '<span>{{body}}</span>' +
        '</can-template>' +
    '</my-email>'
);

setting the stache contents as a string seems worst… the same solution but using a file would be nice

link: https://v3.canjs.com/doc/can-component/can-template.html

I’m not even sure how that example works but a multi line string does not seem like the best option
using steal for fetching the stache file
you can register a partial within the stache file
Nico R.
@nriesco
May 24 2018 21:55
this seems to work, it would be perfect if I could define it in a file instead of inline but still it works:
https://v3.canjs.com/doc/can-stache.tags.named-partial.html#___partialName__BLOCK___partialName__
const view = require("mystachefile.stache!steal-stache");
stache.registerPartial("item.stache", view);

var itemsTemplate = stache("{{#each(items)}}{{>item.stache}}{{/each}}");
Nico R.
@nriesco
May 24 2018 22:00
so mystachefile.stache would be in the same directory? what does !steal-stache mean?
Julian
@pYr0x
May 24 2018 22:01
you dont need !steal-stache if you are using steal and register the stache plugin
mystachefile.stache have to be in your source folder if you are using steal
./mystachefile.stache would mean to have your file right next to your .js file
Nico R.
@nriesco
May 24 2018 22:30
this worked really good:
{{<theTemplate}}
  complex code here
  {{element}}
{{/theTemplate}}


{{#if(condition1)}}
  <div class="container">
    <div class="container-element">
      {{>theTemplate}}
    </div>
  </div>
{{else}}
  {{>theTemplate}}
{{/if}}
Chasen Le Hara
@chasenlehara
May 24 2018 22:39
+1 for inline partials, they were one of my favorite features that we added in CanJS 3
Also @nriesco to answer your question from yesterday:
could it be that when calling the component I have <my-compoenent current:bind=“element" /> and I’m not defining required at all?
That sounds exactly like what that warning is saying, if required is otherwise undefined in your view-model.
Nico R.
@nriesco
May 24 2018 22:58
so I guess checking {{#if(required)}} would be a solution