These are chat archives for canjs/canjs

28th
Apr 2015
Jan Jorgensen
@ramblinjan
Apr 28 2015 19:21
Any suggestions for a can/control/modifier/key replacement?
Justin Meyer
@justinbmeyer
Apr 28 2015 19:22
why do you need a replacement?
are you installing via bower?
cc @daffl
we should add those plugins back into 2.2
Jan Jorgensen
@ramblinjan
Apr 28 2015 19:22
It has a warning that it's undocumented/probably getting removed
if that's not the case, I won't worry about it
Justin Meyer
@justinbmeyer
Apr 28 2015 19:23
that is the case
but there is no replacement
Adam L Barrett
@BigAB
Apr 28 2015 19:23
I just split that plugin to it's own repo, so I could remove the warning from the repo, and leave it in the README
Justin Meyer
@justinbmeyer
Apr 28 2015 19:23
the solution is to probably to give it is own repo
Ilya Fadeev
@ilyavf
Apr 28 2015 20:53

Hi guys. I need to attach a method to a component's prototype to be able to call it from inside event handlers.
Currently I found only one way to do this by declaring it within the events config:

var MyComponent = Component.extend({
  events: {
    '{viewModel.someProp} change': function(){
      this.myMethod();
    },
    myMethod: function(){ /* some action */ }
  }
})

Is this the right approach? Here is jsfiddle: http://jsfiddle.net/rg98749a/

Matthew Phillips
@matthewp
Apr 28 2015 20:55
that's a common pattern yes
you can also do
"{viewModel.someProp} change": "myMethod"
for a simple example like that
Marshall Thompson
@marshallswain
Apr 28 2015 21:08
Is there any way to use can-import to add to the current stache scope?
Something like:
<can-import from="models/customer"/>
<data-table model="{CustomerModel}">
</data-table>
Matthew Phillips
@matthewp
Apr 28 2015 21:10
Actually @daffl just added a feature that lets you pull out a component's viewModel into the current scope
It will be coming in 2.3
But I don't think it will work on can-import... yet
That's a great idea though
David Luecke
@daffl
Apr 28 2015 21:11
But I think he's asking about something like
<can-import from ="models/customer">
  <data-table model="{.}" />
</can-import>
Matthew Phillips
@matthewp
Apr 28 2015 21:11
yeah
David Luecke
@daffl
Apr 28 2015 21:11
Which would be kind of what you're working on right?
Matthew Phillips
@matthewp
Apr 28 2015 21:11
yeah
probably not {.}
that would be can-import's viewModel
maybe {value}
haven't defined this yet, but yeah we can do that
David Luecke
@daffl
Apr 28 2015 21:12
Ah. Yeah, that would work nicely with promises
Matthew Phillips
@matthewp
Apr 28 2015 21:12
yep
can-import's viewModel will be a duck-typed promise
Marshall Thompson
@marshallswain
Apr 28 2015 21:13
So are you thinking of applying the syntax from #1649 to can-import?
<can-import [CustomerModel]=“models/customer.js”/>
Matthew Phillips
@matthewp
Apr 28 2015 21:14
well, the example @daffl gave will be coming soon
Something like you are suggesting would be a little harder because IIRC can-import's are not currently left in the template
David Luecke
@daffl
Apr 28 2015 21:14
It looks a little different
Matthew Phillips
@matthewp
Apr 28 2015 21:14
but i do like that idea
<can-import [CustomerModel]="{value}" from="models/customer.js" />
would be how it would work
David Luecke
@daffl
Apr 28 2015 21:15
<can-import from ="models/customer">
  {{#if isResolved}}
    <data-table model="{value}" />
  {{else}}
    <loading-indicator></loading-indicator>
  {{/if}}
</can-import>
Marshall Thompson
@marshallswain
Apr 28 2015 21:35
So is {value} the name of the var you’re importing from the file?
as in import {value} from “filename”;
David Luecke
@daffl
Apr 28 2015 21:35
No. Basically can-import has a Deferred as its context
so you can show loading indicator etc.
Marshall Thompson
@marshallswain
Apr 28 2015 21:35
I see.
David Luecke
@daffl
Apr 28 2015 21:35
{value} is the resolved value
so whatever the module returns