Currently I am building an ember.js component which has 2 modes, display and edit. When the component is in display mode, it inline renders the template string, which is a property of an associated model. When in edit mode, the component displays the template string in a content editable. I had to make the component re-initialize upon mode toggle by putting 2 instances of the component in a template if/else statement. The following code in my component enables this:
`import layoutDefault from '../templates/components/positionable-element-default'`
.....
layout:Em.computed(->
if @.get('layoutComponent.displayMode')
Ember.HTMLBars.compile(@.get('regionModel.textContent'))
else
layoutDefault
)
My idea for solving render failing to strip out the { and } characters of the template string and then recompile after alerting the user of the error.
I tried putting the compile function in a try catch but nothing is caught , presumably because its not the compiling that is the problem but rather the rendering.
Upon some research, I found Why Ember.onerror() not capturing the Assertion Failed error.? but it looks like I will never be able to catch assertion errors in production. Therefore my question is: is possible to ascertain whether or not a template string will render properly or not ? Or is this kind of functionality outside the scope of ember's capabilities ? Pointers much appreciated :)
Aucun commentaire:
Enregistrer un commentaire