@solid-js/signal

Function based event system. Can replace classic event implementation, with strong typing. Inspired from Robert Penner's AS3 Signals.

Usage no npm install needed!

<script type="module">
  import solidJsSignal from 'https://cdn.skypack.dev/@solid-js/signal';
</script>

README

solid-js

TODO : New v1 alpha DOC

Everything bellow this line is for v0.1, not v1.0-alpha

Signal event system

Signal is an object based event system.

Concept

Classic events dispatcher systems are string based, which can be difficult to track across your application.

document.addEventListener( "which one already ?" );

With Signal, every "event" is represented by an object with add and dispatch methods.
Messages can be dispatched and followed more fluently thanks to its object notation.

const onModelReady = Signal()

onModelReady.add( function ( state ) {
    console.log('Model ready state changed', state.ready) // true
})

onModelReady.dispatch({
    ready: true
})

Install

npm i -S @solid-js/signal

Size

TODO

Dependencies

TODO

History

This library comes from Robert Penner's AS3 Signal. This is not a port, it has been entirely remade for Typescript and Javascript.

Works well with classes

Signal can work inside a functionnal workflow, as well as in a object oriented paradygm. Here is an example of Signals implements to create clear communication flow between objects.

class UserModel
{
    readonly onReady            = Signal();
    readonly onUserConnected    = Signal();
    readonly onMessageReceived  = Signal();

    [...]

    userConnectedHandler ( rawUserData )
    {
        const user = new User( rawUserData );
        this.onUserConnected.dispatch( user );
    }
}

class UserView
{
    constructor ( userModel )
    {
        userModel.onUserConnected.add( this, this.userConnectedHandler )
    }

    [...]

    userConnectedHandler ( user )
    {
        console.log( user );
    }
}

Typescript

This library comes with Typescript definitions. Source code is pre-compiled to Javascript modules so Typescript is opt-in and up to you. Signals can have static types set to help error checking in your project.

More ...

Event Signal TODO State Signal TODO

Solid-js

TODO