Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

satya164/gjs-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GNOME JavaScript helpers

These helper modules are made to make working with GJS easier. Especially when you're coming from a node environment.

Currently these include,

  • Promise implementation based on the ES6 spec.
  • Polyfill for setTimeout and setInterval.
  • Promise based library for working with files.
  • Promise based library for fetching data over network.

Usage

Since I'm not aware of any good module architecture for GJS, you've to manually copy the files to your project directory and use them. Which means you'll miss on updates.

First you'll need to add the current directory to search path.

imports.searchPath.unshift(".");

Then, say you want to use the Promise library, place the promise.js file in a directory named helpers, and import it,

const Promise = imports.helpers.promise.Promise;

Now you have access to the Promise object for use.

let promise = new Promise((resolve, reject) => {
    let file = Gio.File.new_for_path("/tmp/new_dir");

    file.make_directory_async(GLib.PRIORITY_DEFAULT, null, (source, res) => {
        resolve(source.make_directory_finish(res));
    });
});

promise.then(() => print("Directory created successfully!"));
promise.catch(() => print("Directory creation failed!"));

Note that the Promise library automatically catches synchronously thrown errors and the promise fails.

Running tests

Tests are written using a custom tool (included as litmus.js in the repo). To run tests, simply cd into the src directory and run the intended test file.

cd src
gjs promise-test.js

About

GNOME JavaScript helpers for async tasks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published