Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jslights

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jslights

JavaScript module namespacer and event emitter

  • 0.6.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

jsLights

JavaScript module namespacer and event emitter

Usage

For apps using singletons which needs to be globally available but depending on other singletons inside application

For example displaying username after user had logged in:

// simple function saying hello to given user
function SayHello(username) {
    console.log("Hello ", username);
}

// class (defined using ES6 syntax) which needs to be instantiated after user had logged in
class Welcome {
    constructor() {
        app.sayHello(app.user.username);   
    }
}

// class extending jsLightss built in event emitter
class User extends jsLights.EventEmitter {
    constructor() {
        this.login();
    }
    
    login() {
        this.username = "johnDoe";
        this.trigger("login");
    }
}


Instantiate singleton

// create "new SayHello()" and bind it in "app.sayHello"
jsLights.instantiate('app.sayHello', SayHello); 

// create "new User()" and bind it in "app.user" 
// after app.sayHello is initialized
jsLights.instantiate('app.user', User, 'app.sayHello'); 

// create "new Welcome()" and bind it in app.welcome
// after DOM is ready
// after app.sayHello is initialized
// after app.user is initialized and triggered "login" event
jsLights.instantiate('app.welcome', Welcome, [
    'onDocumentReady',
    'app.sayHello',
    'app.user->login'
]);

Building

For now, to be able to build minified file, you need to have "babel", "browserify" and "uglifyjs" installed globaly (this should be changed in the near future)

FAQs

Package last updated on 06 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc