Results 1 to 6 of 6

Thread: Importing JS libraries for use in Lianja

  1. #1
    Junior Member
    Join Date
    Jul 2015
    Posts
    25

    Importing JS libraries for use in Lianja

    Hi all,

    I'm trying to import an external library into lianja. I've learned about how it essentially uses Node.js implementation and the syntax required, but am still having issues. Here's what I'm currently trying:

    "library.js", one of my app's js files.
    Code:
    function func1(){
        print("library working!");
    };
    
    module.exports.func1 = func1;
    In my section's custom library, as a global:
    Code:
    var mylib = require("app:/library.js");
    Click delegate of a button in my section:
    Code:
    mylib.func1();
    I believe this should print "library working!" to the console, but instead the log tells me "TypeError: Result of expression 'mylib.func1' [undefined] is not a function."

    Has anyone else tried importing JS libraries into Lianja?

  2. #2
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    1,942
    Hi Joanna,

    the Lianja require() doesn't seem to return the library object. Try just calling the function.

    Hank

  3. #3
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,769
    Hi Hank

    it appears that require() in desktop apps is just including the JavaScript at that point. It's acting like an include(). Please submit a ticket as I think it should operate in the same way as node.js require() and return the module.exports object so that it is consistent.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  4. #4
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    1,942
    Hi Barry,

    Done with sample code. I remember you saying/writing at some time that it worked like include. Having it work like the JavaScript library (which already ships with Lianja) would be great.

    thanks,

    Hank

  5. #5
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,769
    Hi Hank,

    I have now corrected this in v2.1. It returns the module.exports object now.

    Just an FYI there are four functions that work in a similar fashion.

    var mylib = require("some_filename.js");
    var mylib = require_once("some_filename.js");
    include("some_filename.js");
    include_once("some_filename.js");

    These originally were implemented in the same way as PHP but later changed in the web/mobile client so I have now made require() and require_once() return the module.exports object for consistency. require_once() keeps an internal cache and knows if the library has been loaded already so its module.exports object is used rather than loading the library again. The same goes for include_once().

    Also remember that filenames can be prefixed with app:/ or lib:/ which is expanded for you to the full filename path.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  6. #6
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    1,942
    Fantastic, as usual. Thanks.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us