1.0.11 • Published 9 months ago

@quazardous/quarkernel v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

QuarKernel

Micro Custom Event Kernel.

Features

Helps structuring your app with events.

  • Modern: ES6, Async() support with Promise
  • Dependency support: easily handle async resource dependencies
  • Composite event: handle complex logic with a common event pipe
  • Shared context: use event data to share variable

Install

npm i "@quazardous/quarkernel"

Basic usage

Define event listeners across your app modules with dependency support.
Share context between components.

import { QuarKernel, QuarKernelEvent as QKE } from '@quazardous/quarkernel';

// singleton
const qk = new QuarKernel();

qk.addEventListener('my_event', (e) => {
    // something
    notNeeded();
});

// your module foo does some init stuff
qk.addEventListener('my_event', async (e) => {
    // something async
    e.context.needed = await needed();
}, 'foo');

// somewhere else in your app your module bar is waiting after foo to set a specific context
qk.addEventListener('my_event', (e) => {
    // something after the async callback
    needing(e.context.needed);
}, 'bar', 'foo');

// call everything
qk.dispatchEvent(new QKE('my_event')).then((e) => {
    // event my_event fully dispatched
    happyEnd();
});
// or await qk.dispatchEvent(new QKE('my_event'));

Composite event

Composite event are auto dispatched when a specific list of events are dispatched.

ie. You set a composite event C on A+B. Your code dispatches A, then B. C is auto dispatched after B.

...
// init
qk.addCompositeEvent(['A','B'], (stack) => new QKE('C'));
...
qk.dispatchEvent(new QKE('A'));
...
// this will auto dispatch C
qk.dispatchEvent(new QKE('B')); 
1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago