JSFiddle - React, Tailwind, and code Playground

by Avi Algaly

JavaScript

// are u here? of course waiting u to fninsh so i can look a bit on it
// OK, so, from my story - this is me :)
var Michael = {
    // I can fire events so I should know who listens for them
    // here I am storing the listeners
    // I can fire several events, so to know who listens to which event
    // I hold the following stucture:
    // Array of Arrays
    // [
    //     "event1": [listener1, listener2],
    //     "event2": [listener3, listener4, listener5]
    //     ...
    // ]
    // OK? ?ok (where is it in the code?)... wait, it's coming
    
    _eventListeners: [],
 
    // this is what I can do - build a project by requirements
    makeProject: function(reqs) {
        // making the project
        alert("Starting the project");
        var halfProject = Math.floor(reqs / 2);
        for(var req = 0; req < reqs; req++) {
            if(req === halfProject) {
                this.trigger("halfProjectDone");
            }
        }
        this.trigger("projectDone");
    },
        
    // here is the declaration of functionality of events
        
    // adding event listener (public function for clients)
        //write name of event type and listener 4 example : 'click' ,'myClickHandler'
        //which tell us that : client wants to execute his 'myClickHandler' function when 'click' occures in me (I trigger 'click' event)ok
    addEventListener: function(eventType, listener) {
        // gets: eventType - which event to listen to
        //       listenet - pointer to callback function, that will be called
        // signature + in parameters - OK?ok
        
        // we are checking is the event type already declared and if not:
        // we declare it
        if(typeof this._eventListeners[eventType] == "undefined") {
            this._eventListeners[eventType] = [];
            // yessorry to correct u master! :D
            // now we have this._eventListsners[eventType] = [];
            // eventType event type with empty array of...