0.0.14 • Published 10 months ago

@protorians/signalable v0.0.14

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Protorians Signal

Protorians Signal is a Javascript event handler.

The primary goal is to have a list of functions typed with the pair name: arguments, all from an existing object.

Multiple signal

It is a signal that manages several types of signals. The goal is to have a grouping of signals within the framework of a more global use.

Use cases

It can be implemented as part of a multi-level treatment. Let's imagine that we have a class that has the following methods:

interface IGenV{
  
}

class Genv implements IGenV{
  
   parse(){
     //...
   }
  
   commit(){
     //...
   }
  
   push(){
     //...
   }
  
}

In our example, each method can call a type of signal.

How it works

  • To begin, you would need to create the signal typing.
type IMySignal = {
   initialize: boolean;
   parse: string[];
   commit: string[];
   push: boolean;
}
  • Then, build your signal
this.signal = new Signalables<IGenvable, IMySignal>(genvableInstance)
  • Set headphones
class Genv {

   signal: ISignalable<IGenV, IMySignal>
   files: string[]
   validated: boolean = false

   constructor(instance: IGenvable, files: string[]) {
     this.files = files;
     this.signal = new Signalables<IGenvable, IMySignal>(instance);
   }

   initialize() {
     this.signal.listen('parse', context => console.log(context))
     this.signal.listen('commit', context => console.log(context))
     this.signal.listen('push', context => console.log(context))
   }

   run() {
     this.initialize()
   }

}
  • Trigger eavesdropping
class Genv {
  
   //..

   parse() {
     this.signal.dispatch('parse', this.files)
   }

   commit() {
     this.signal.dispatch('commit', this.files)
   }

   push() {
     this.signal.dispatch('push', this.validated)
   }

   //..
}

Autonomous signal

It is a singular signal unit which is managed independently. The goal is to manage a single type of isolated signal within the framework of very precise use.

Use cases

It can be implemented as part of a single-level treatment. Let's imagine that we have a function doing a single processing but need to trigger a signal when the processing is carried out:

type IGenV = {}
function genv(): IGenV {
}

How it works

  • To begin, you would need to create the signal typing.
type IMySignal = boolean
  • Then, build your signal
const signal = new Signalable<IGenvable, IMySignal>(genvableInstance)
  • Set headphones
function genv(): IGenV {
   // ...
     signal.listen(context => console.log(context))
   // ...
}
  • Trigger eavesdropping
mySignal.dispatch(true)

Protorians ;)

0.0.13

10 months ago

0.0.14

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago