Coder Social home page Coder Social logo

webaxol / pluglightjs Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 569 KB

A light-weight JavaScript framework designed to create flexible and maintainable projects with a modular and hierarchical approach

License: MIT License

JavaScript 100.00%
event-management-system flexible framework javascript lightweight-framework decoupled-components microkernel

pluglightjs's Introduction

OooOOo.   o               o                o           OooOoo .oOOOo.  
O     `O O               O       o        O                O  o     o  
o      O o               o                o      O         o  O.       
O     .o O               o                O     oOo        O   `OOoo.  
oOooOO'  o  O   o  .oOoO O       O  .oOoO OoOo.  o         o        `O 
o        O  o   O  o   O O       o  o   O o   o  O         O         o 
O        o  O   o  O   o o     . O  O   o o   O  o   O     o  O.    .O 
o'       Oo `OoO'o `OoOo OOoOooO o' `OoOo O   o  `oO `OooOO'   `oooO'  
                       O                O                              
                    OoO'             OoO'                              
----------------------------------------------------------------------------
**Data-driven light-weight JavaScript framework for real-time applications** 

License: MIT

Introduction

PlugLightJS is a simple javascript framework designed to build data-driven applications with a modular approach easily. Its architecture was inspired by an existing framework called ECSY.js; I decided to make my framework, to gain more control of some design aspects like event management and object construction and allocation.

Usage

//  First, create a 'World' instance: the top-level class that controls the framework components

const world = new World()

Create Services

Services contain code that is executed every frame by the World class. They are implemented as 'Service' sub-classes

import { Service } from 'pluglightjs'; // You may need to import the Service class
// Make a 'Service' sub-class: you can add custom methods and attributes

class ExampleService extends Service{

  constructor(){
    super();
    // etc...
  }

  execute(){
   // Your code!
  }
}

// Then, register your service ( service name, service instance )

world.registerService('exampleService', new ExampleServiceA());

Create Events

Here are the main functions to work with events in pljs:

world.registerEvent('eventName'); // create event
world.registerServiceToEvent('serviceName','eventName'); // make service an event listener
world.notifyEvent('eventName', { info : 'eventInfo' }); // emit event

Lets implement that with a brief example:

class EventEmitter extends Service{

    constructor(){
        super();
        // etc...
    }

    execute(){

        // Emit event
        
        this.world.notifyEvent('exampleEvent');
    }
}

class EventReceiver extends Service{

    constructor(){
        super();
        // etc...
    }
  
    // event-handler class (on + event name)

    onexampleEvent(){
        console.log('event received');
    }
}

world.registerEvent('exampleEvent');

world.registerService('emitter' , new EventEmitter());
world.registerService('receiver', new EventReceiver());

world.registerServiceToEvent('receiver','exampleEvent');

Framework Execution

world.execute();    
world.pauseExecution();

Contribute

git clone https://github.com/WebAxol/PlugLightJS

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.