Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember bound block helper

I'm wondering if the registerBoundHelper in ember was ever meant to be able to handle the block style helpers. For example, I created the following:

Ember.Handlebars.registerBoundHelper('unlessUndefined', (context, options) ->
  unless typeof context == "undefined"
    return options.fn(this)
  else
    return options.inverse(this)
)   

The idea being to use it as such:

{{#unlessUndefined choice}}
  {{#if choice}}
    <p>You chose yes</p>
  {{else}}
    <p>You chose no</p>
  {{/if}}
{{else}}
  <p>Make a choice</p>
{{/unlessUndefined}}

The option.fn(this) parts of things don't appear to render any output. When doing this I get an error in the console that says: "You can't use appendChild outside of the rendering process"

If this isn't possible, perhaps somebody can suggest another way to achieve a conditional block that will only show if the bound value isn't undefined?

like image 678
David Monagle Avatar asked Jan 11 '13 04:01

David Monagle


People also ask

What is helper in Ember JS?

A helper is usually a simple function that can be used in any template. Ember comes with a few helpers that can make developing your templates a bit easier. These helpers can allow you to be more dynamic in passing data to another helper or component.

What is Mut in Ember?

Let's talk about Ember's {{ mut }} HTMLBars helperThe mut helper returns a mutable object which is an object that responds to update . The action helper knows about these objects and knows to call update (passing in the new value) when given a mutable object .

What is computed in Ember JS?

What are Computed Properties? In a nutshell, computed properties let you declare functions as properties. You create one by defining a computed property as a function, which Ember will automatically call when you ask for the property. You can then use it the same way you would any normal, static property.


1 Answers

I just spent a bunch of time fighting this and found a fix of sorts. I looked at the pull request with the implementation of the registerBoundHelper method.

I added the following above this line: https://github.com/emberjs/ember.js/pull/1274/files#L0R357

Ember.run.scheduleOnce('render', view, 'rerender')

It looks like the boundHelper method just wraps the original helper method and creates an anonymous view. The only problem is that the observer puts the anonymous view into render mode without putting the original view into the same first.

At least that's what I think is going on. Anyway, it works for me now. Maybe this is a bug?

like image 68
Paul Dix Avatar answered Oct 17 '22 22:10

Paul Dix