signals-slots-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

signals-slots-ts

A simple example of the signals/slots observability pattern, written in TypeScript.

Usage

  • Both CommonJS and ESM entry files are provided.
// CommonJS
const { createSignal } = require('signals-slots-ts');

const myComplexData = myComplexDataFactory();
const mySignal = createSignal(myComplexData);

// ESM
import { createSignal } from 'signals-slots-ts';

const myComplexData = myComplexDataFactory();
const mySignal = createSignal(myComplexData);
  • Connecting / disconnecting callbacks
import { createSignal } from 'signals-slots-ts';

const myComplexData = myComplexDataFactory();
const mySignal = createSignal(myComplexData);

const onMyComplexDataChange = (newComplexData) => {
    console.log(newComplexData);
};
mySingal.connect(onMyComplexDataChange);
mySignal.value.someNumberFieldOfMyComplexData += 1;
// Updated data logged to console.

mySignal.disconnect(onMyComplexDataChange);
mySignal.value.someNumberFieldOfMyComplexData += 1;
// Updated data not logged to console.

Package Sidebar

Install

npm i signals-slots-ts

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

24 kB

Total Files

16

Last publish

Collaborators

  • smithky3