You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Patrick Mueller (Commented) (JIRA)" <ji...@apache.org> on 2012/03/05 15:09:58 UTC

[jira] [Commented] (CB-296) Cordova.hasResouce doesn't work for Android

    [ https://issues.apache.org/jira/browse/CB-296?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13222363#comment-13222363 ] 

Patrick Mueller commented on CB-296:
------------------------------------

bq. ... which you can now check by calling require() on a specific plugin and seeing if it returns a truthy value.

calling {{require(<some module name>)}} when the specified module is not available will throw an exception, so ... that's not a good way to check.  This should work:

{noformat}
function hasResource(moduleId) {
    try {
        return require(moduleId)
    }
    catch(e) {
        return false
    }
}
{noformat}

But what's the use case here?  Maybe this was for a non-core plugin?  How do plugins register themselves so that some other piece of code can ask if they're loaded?  Do we eventually want to move them into the module system?  If so, we may want to add an additional API such as {{cordova.isModuleAvailable(<some module name>)}} which would return a boolean indicating whether a module was available or not.  Node.js has an API called {{require.resolve(<some module id>)}}, which resolves a module name to a file name without loading it, but also throws an error if the module isn't available.
                
> Cordova.hasResouce doesn't work for Android
> -------------------------------------------
>
>                 Key: CB-296
>                 URL: https://issues.apache.org/jira/browse/CB-296
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 1.5.0
>         Environment: Android
>            Reporter: Takashi Okamoto
>            Assignee: Filip Maj
>
> I tried Cordova.hasResource  with Cordova 1.5.0 snapshot on Android.
> I found Cordova.hasResouce doesn't work and not defined in cordova-1.5.0.js
> cordova.js.base may not include cordova-1.5.0.js and 
> it seems build.xml problem.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira