This.get('filter')('') : why this is not throwing an error?

Hi,

It is week no2 for me in ember and I am coming from a rails-vanilla js background.

I would love someone to explain to me what this is:

this.get('filter')('').then((results) => this.set('results', results));

on Building a Complex Component - Tutorial - Ember Guides app/components/list-filter.js.

Point (1)—> the source of my confusion? this.get(“filter”)… and then follows another parens !!! ( ’ ’ )… why is this not throwing an error? I ve read the api doc def of get but there was nothing. What kind of syntax is that?

Point (2)---->And to which filter is the author referring? because on this. I see no “filter”, property…

Also, the results param of the promise is predefined? Why nobody is telling to us if so?

A great guide so far but this section needs improvement…

this.get('filter') is an action that is passed to be component in the template: filter=(action 'filterByCity'). This means that the component’s filter property is bound to an action created from the filterByCity property of the parent context.

this.get('filter')('') is calling that action with the parameter ''. If you search for the implementation of filterByCity (the action passed to the component as filter), you’ll see the following: if (param !== '') {. In short, passing an empty string means that you get all results, instead of filtering.

(results) => this.set('results', results) is an arrow function.

I don’t quite understand this question, but I believe that the link to the arrow functions documentation will help.

1 Like