Skip to content

postpostscript/Qjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qjs

Introduction

Qjs is a Javascript module framework written by Daniel Wilson and inspired by Sam Weaver. It is similar to Require.JS, but with additional features tailored towards rapid application iterational development in modern Javascript web design.

How does it work?

Qjs is rather simple, especially if you have worked with Require.JS before. Take a look at this snippet of an example module:

(function(Q){
    var module = new Q.module('string-reverser');

    module.reverseString = function(stringToReverse) {
        return stringToReverse.split('').reverse().join('');
    };
})(Q);

This module, called string-reverser, has one method. It simply takes an input string and reverses it. Let's look at how it could be used.

var stringReverser = Q.getModule('string-reverser');

console.log(stringReverser.reverseString("dlrow olleh"));

This snippet would output "hello world" on the console.

Modules can also be accessed, by calling the Q function directly, instead of using getModule.

var stringReverser = Q('string-reverser');

This syntax should be avoided, and is only included for sake of backwards compatibility. The reasoning for this is that the global variable require is a reference to the Q global variable. Therefore, you can also use this syntax, which may be easier for those who have worked with Require.JS.

var stringReverser = require('string-reverser');

Modules can also automatically implement jQuery. You can do this by setting the jQueryRequired variable on the module object, in the code of your module.

module.jQueryRequired = true; // or false...

Qjs includes some built-in events that make modern web development a bit easier. Events can be bound and triggered on modules using the following syntax.

module.on('custom-event',function(){
    // ...
});

// Later, outside the module declaration:

definedModule.trigger('custom-event');

Built in events in Qjs include:

  • init: Is triggered before page load, in the tag.
  • ready: Is triggered on document ready (through jQuery $(document).ready(...);
  • jQueryNotIncluded: Is triggered if jQuery is not included on the page.

We hope that you enjoy Qjs as much as we do.

Contribution Guide

If you desire to contribute, fork, and submit a pull request. Please follow the following guidelines:

  • Keep code clean and easily understandable.see note 1
  • Comment your code when necessary. Explaining the why is often more useful than explaining the how.
  • Use Object Oriented coding style whenever possible.

Note 1: Whenever possible, keep close with Google's Closure Javascript Style Guide.

TODO

  • Make Q modules fit CommonJS Module Specification 1.1
    • Note, this may be difficult and noncondusive to future development, on hold for now
  • ✔️ Write documentation
  • ✔️ Unit testing

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors