Index ¦ Archives  ¦ Atom  ¦ RSS

Enyo - Service Components

A feature I totally missed before and only saw after reading the db8 tutorial. If you have a service that you call different methods of, you probably do what I used to do:

enyo.kind({
    ...
    components:[
        {name:"downloader",kind:"PalmService",service:"palm://com.palm.downloadmanager/"}
        ...
    ]
    ...
    startDownload:function(){
        this.$.download.call({
            target:"http://fahhem.com/"
        },{
            method:"download",
            onSuccess:"downloadSucceeded",
            onFailure:"downloadFailed"
        });
    }
    ...
});

But now, I have a saner way to deal with different methods:

enyo.kind({
    ...
    components:[
        {kind:"PalmService",service:"palm://com.palm.downloadmanager/",components:[
            {name:"download",method:"download",onSuccess:"downloadSucceeded",onFailure:"downloadFailed"}
        ]}
    ]
    ...
    startDownload:function(){
        this.$.download.call({target:"http://fahhem.com/"});
    }
    ...
});

Now you can handle the same service with multiple methods with shorter calls and easier debugging.

© Fahrzin Hemmati. Built using Pelican. Theme by Giulio Fidente on github.