btca-client

    2.0.4 • Public • Published

    btca-client

    BTCA Client library. See JavaScript Bridge 3.0 documentation for available actions.

    Installation

    npm install btca-client --save

    You can now import btca-client and optionally include a CSS reset.

    import BTCAClient from 'btca-client';
     
    import 'btca-client/css/btca.css';

    You can also use the standalone UMD build via CDN.

    <script src="https://unpkg.com/btca-client/lib/btca.min.js"></script>
     
    <link href="https://unpkg.com/btca-client/css/btca.min.css" rel="stylesheet">

    Usage

    Initialise a new instance of the BTCAClient.

    var BTCA = new BTCAClient({
      handle: 'MY_BTCA',      // unqiue handle to identify BTCA
      cache: false,           // caches requests (useful for debugging)
      disableEvents: false,   // disables default events (see below)
      log: false              // logs actions to console
    });

    Send Request

    There are various ways to perform a JSBridge request.

    // define your JSBridge action
    var data = {
      action: 'getEntity',
      params: {
        entityName: 'story',
        id: 123
      }
    };
     
    // send with anonymous callback
    BTCA.send(data, function(result, requestId, error) {
      console.log(result);
    });
     
    // send with callback reference
    BTCA.send(data, handleRequestResponse);
     
    // send with btcjsapi:// schema and named jsListener callback
    BTCA.send('btcjsapi://getList?entityName=story&id=123&jsListener=handleRequestResponse')

    Disabling Default Events

    By default, JSBridge actions are bound to various anchor click events. If you'd like to disable this and handle it yourself you may set disableEvents: true when initialising.

    • Anchor tags with mailto: are parsed and will send a sendMail action.
    • Anchor tags with an absolute URL or rel=app are treated as Hub links and will send an openURL action.
    • Anchor tags with an http(s) link or rel=external are treated as external links and will send an openURL action.
    • Anchor tags with btcjsapi:// will send the specified action.

    Install

    npm i btca-client

    DownloadsWeekly Downloads

    24

    Version

    2.0.4

    License

    SEE LICENSE IN LICENSE

    Unpacked Size

    176 kB

    Total Files

    13

    Last publish

    Collaborators

    • bigtincan