Git Product home page Git Product logo

gjs-helpers's Introduction

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

gjs-helpers's People

Contributors

satya164 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gjs-helpers's Issues

Common JS Compatibility

The fellows in GNOME recommend bundling external modules into the main file for code reusability.
It's easy as:

  • create a package.json with a main field pointing to a main js file
  • create a main js file which requires your modules

THANK YOU FOR YOUR WONDERFUL WORK

Add LICENSE

Hi,
These helpers are really great, and I'm using them in an extension.
I'd like to publish my extension, but unfortunately there is no license in this repo.
In fact, the extensions.gnome.org site explicitly asks to confirm that "I verify that my extension can be distributed under the terms of the GPLv2+" when you want to upload a new extension.

It would be great if you could add a compatible license! Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.