Firing events in FireBreath - javascript

I am writing a wrapper class for an activex control using a FireBreath plugin.
In the FireBreath activex wrapper example linked to from the documentation of FireBreath the author of the project uses FireEvent to asynchronously fire the event from the activex container class.
But the documentation of FireBreath now has a note under the method FireEvent which says:
"Note: Firing events in this manner is deprecated as of FireBreath 1.5.0"
And also in the example the events are not registered in the root JSAPI object using this format:
FB_JSAPI_EVENT()
So is this the right way of doing it? Or is it possible to call the events from the container class using the
fire_event()
method?

Both work the same way, the reason that calling FireEvent directly is deprecated is just that it's easier to make mistakes with the parameters you pass in.
You can use either method, but I recommend that you use FB_JSAPI_EVENT simply to keep things more clear.

Related

Best way to register event in Angular

As far as I know, we can use .bind and .on api from jqlite or .addEventListener native api to register event. Many people are using jqlite api to register event since angular 1.x offers that. But what about Angular 2? Does Angular 2 still offers jqlite api, or should we stick with the native api since it is safer that way.
Also, regarding the performance between .on and .addEventListener . Which one is better?
You shouldn't touch the DOM directly in angular2 application. It makes impossible to run your application in WebWorkers or on a server side. Use (event)="someHanlder()" notation instead. See this plunker.
#Component({
selector: 'some-component',
// in "template" you can add handlers for child elements events
template: `
<button (click)="handleClickChild($event)">here</b>
`,
// in "host" you can add handlers for host element events
host: {
'(click)': 'handleClickHost($event)'
}
})
class SomeComponent {
handleClickHost(event) {
// some logic
}
handleClickChild(event) {
// some login
}
}
Does Angular 2 still offers jqlite api, or should we stick with the native api since it is safer that way.
Angular 2 does not offer jqlite.
Also, regarding the performance between .on and .addEventListener . Which one is better
Use .addEventListener as that is the DOM official way.

dojo.connect(obj, event, context, method, dontFix); to dojo on amd 1.9

I have code snippet available written in dojo 1.3.
dialogWidget._proxyConnects.push(dojo.connect(
newDialog._fadeIn,
"onEnd",
dialogWidget,
"onLoad"
));.
When I write on instead of the dojo.connect (After requiring the dojo/on) gives me the error target unspecified Can any one help me in this regard?
As I mentioned in the answer to similar question you made, this might either because of an update or because your code accesses a private property that doesn't exist anymore.
Try to understand what exactly that piece of code was supposed to do, and act accordingly.

Use of this.own() method in dojo

i would like to know the intention of the "this.own()" method in dojo widgets. This method is mentioned in the Dojo Api 1.8 Documentation, for example under diijit/form/button. I did not find anything that made sense to me on google. That is how the method is mentioned:
connect(obj, event, method)
Deprecated, will be removed in 2.0, use this.own(on(...)) or
this.own(aspect.after(...)) instead.
The own function is defined in dijit/Destroyable, which is a base of dijit/_WidgetBase and thus most widgets.
dijit/Destroyable is used to track handles of an instance, and then
destroy them when the instance is destroyed. The application must call
destroy() on the instance in order to release the handles
http://dojotoolkit.org/reference-guide/1.8/dijit/Destroyable.html
http://dojotoolkit.org/reference-guide/1.8/dojo/Evented.html
The short answer is: most of the things that you define inside .own() are getting correctly removed once the widget itself is destroyed. Using .own() prevents memory leaks in your app.
To remove a widget from a page, you can either call destroy or
destroyRecursively on your widget.
When you do that, anything that you added using this.own ( dojo/on,
dojo/aspect, dojo/topic, dojo/router, the creation of a related DOM
node or widget, etc.) will be removed and/or unregistered
automatically. This is implemented via the dijit/Destroyable
interface.
Understanding-WidgetBase-own-td4002453.html
Related Tutorial

Missing properties in window when using a content script

My addon is injecting some content scripts into various websites. After trying to bind onbeforeunload or calling window.location.reload I realized that the window object misses some properties.
Is there a way to binding certain events (onbeforeunload, onunload, etc) while injecting code via page-mod module?
I've created a test add-on, showing that these properties are missing: https://builder.addons.mozilla.org/addon/1037497/latest/
Solutions on how to use them anyway?
Short answer: You add an event listener using addEventListener() method, like this:
window.addEventListener("beforeunload", function(event)
{
...
}, false);
Long answer: For security reasons your content script isn't communicating with the DOM objects directly, e.g. it cannot see any script-added properties. The technical details also list some limitations:
Assigning to or reading an on* property on an XPCNativeWrapper of a
DOM node or Window object will throw an exception. (Use
addEventListener instead, and use event.preventDefault(); in your
handler if you used return false; before.)
In a content script you probably don't want to replace the web page's event handlers anyway, rather add your own - that's what addEventListener() is doing.
Additional reading

What is alternative to jQuery(this) in YUI 3?

I have started coding in yui and already have good knowledge of jQuery ,
I need some information about migrating from jQuery to yui.
What is the alternative to jQuery(this) in YUI?
In most cases, jQuery(this) is done inside event callbacks to wrap the subscribed element with the jQuery API. In YUI3, that's done for you automatically. The this in event callbacks is the Node instance that was subscribed from.
Y.one('#readygo').on('click', function (e) {
this.append("<p><code>this</code> is already a YUI 3 wrapped Node instance.</p>");
});
You may find JS Rosettastone useful. I found it invaluable when I moved to YUI 3 and I will not move back.

Categories