GithubHelp home page GithubHelp logo

th3mouk / reactive-event-dispatcher Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 19 KB

An immutable implementation of the PSR-14 (event-dispatcher) for ReactiveX PHP.

PHP 99.14% Makefile 0.86%
event-dispatcher psr-14 rxphp hacktoberfest

reactive-event-dispatcher's Introduction

Reactive Event Dispatcher // PSR-14

This PHP library provide an immutable implementation of the PSR-14 for ReactiveX PHP.

Latest Stable Version Latest Unstable Version Total Downloads License

Coverage Status Scrutinizer Code Quality

Installation

composer require th3mouk/reactive-event-dispatcher

Usage

Psalm usage is recommended. See relative introduction and documentation.

use Psr\Container\ContainerInterface;
use Rx\Observable;
use Th3Mouk\ReactiveEventDispatcher\Dispatcher;
use Th3Mouk\ReactiveEventDispatcher\Event;
use Th3Mouk\ReactiveEventDispatcher\EventCorrelation;
use Th3Mouk\ReactiveEventDispatcher\Listener;
use Th3Mouk\ReactiveEventDispatcher\ListenerProvider;
use Th3Mouk\ReactiveEventDispatcher\Priority;


$event = new class implements Event {};
$listener = new class implements Listener {
    public function process (Event $event) : Observable {
        return Observable::of(1);    
    }
};

// Link between an event and a listener
// Higher is the priority, earlier is the call
$event_correlations = [
    EventCorrelation::create(
        get_class($event),
        get_class($listener),
        Priority::fromInt(0),
    )
];

// Any object implementing ContainerInterface
// Listeners must be present into
$locator = new class implements ContainerInterface{
    public function get($id){
    }
    
    public function has($id){
    }
};


$listener_provider = new ListenerProvider($locator, $event_correlations);

$dispatcher = new Dispatcher($listener_provider);

$dispatcher->dispatch($event)->subscribe();

Please

Feel free to improve this library.

reactive-event-dispatcher's People

Contributors

th3mouk avatar

Watchers

 avatar  avatar

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.