samedi 31 octobre 2015

emberjs - refactor to component helper

I am migrating some code from ember 1.7.1 and I created my own component helper before there was one in the form of a handlebars helper:

Ember.Handlebars.registerHelper('renderComponent', function(contextPath, propertyPath, options) {
  var context, helper, property;
  context = Ember.Handlebars.get(this, contextPath, options);
  property = Ember.Handlebars.get(this, propertyPath, options);
  helper = Ember.Handlebars.resolveHelper(options.data.view.container, property.component);
  options.contexts = [];
  options.types = [];
  property.bindings.forEach(function(binding) {
    options.hash[binding] = binding;
    options.hashTypes[binding] = "ID";
    options.hashContexts[binding] = context;
  });

  return helper.call(context, options);
});

The helper is called like this:

  {{#each column in columns}}
    <td>
      {{renderComponent item column}
    </td>
  {{/each}}

And would create components from a configuration like this:

App.IndexController = Ember.Controller.extend({
  columns: Ember.A([
   {
      heading: "Heading",
      binding: "name",
      route: "company"
    },
    {
      heading: "Address",
      binding: "address"
    },
    {
      heading: 'full',
      component: 'full-contact',
      bindings: ['name', 'address']
    }
  ])
});

How can I achieve the same thing with the component helper?

I'm thinking specifically about passing arguments and bindings to the component helper? How is that done?




Aucun commentaire:

Enregistrer un commentaire