-
Notifications
You must be signed in to change notification settings - Fork 2
Tips to know
I18n use span Nodes to help working in an asynchronous way. So it's impossible to get a translated string from a syncrhonous method. You can only get a Node or a string Node representation. So this is the way you have to use that if you want to translate a string in a Node attribute. We take the exemple of the placeholder attribute of an input node :
var node = Y.Node.create('<input type="text" />'),
t = __('publish~placeholder.title');
t.after(
'i18n:change',
function(e)
{
node.setAttribute(
'placeholder',
e.translation
);
},
node
);
Each time the i18n node will be translated, it will update the input's attribute.
##Events in views
When you listen to events in your view, it's very important de detach the events handlers on the view destructor. To make this easier, Y.ys.View has a method which store the events handlers as you create them, and which detach each of them on the destructor method. This is how you have to proceed :
…
bindUI: function()
{
this.storeEvent(
this.after(
'valueChange',
this.syncUI,
this
)
);
this.storeEvent(
Y.on(
'key',
this.doSomethingWithKey,
this
)
);
this.storeEvent(
this.get('model').after(
'trucChange',
function()
{
alert(this.get('model').get('truc'))
},
this
)
);
}
…
All theses events will automatically be detached if you let your view call the Y.ys.View destructor method. Don't forget to call it if you override it in your class :
…
destructor: function()
{
MyClass.superclass.destructor.apply(this, arguments);
delete this._foo;
delete this._bar;
}
…