Fork me on GitHub

How to deploy a piece of code as text on site:

see results in the console also

the code is generated by JavaScript

HTML code:

                            
                                <div class="highlight--piece--of--code">
                                    <pre>
                                        <code>
                                ****************************** Your code here *******************************************************************
                                        </code>
                                    </pre>
                                </div>
                            
                        

CSS code:

                            
                                .highlight--piece--of--code {
                                background-color: #08090a;
                                color: #f8f8f3;
                                border-radius: 5px;
                                overflow-x: auto;
                                }
                            
                        

Zhan Zhuridov's Observer. Initial variant:

The second variant is in my GHgists:

https://gist.github.com/Hacking-NASSA-with-HTML/60367e3fbeb7140a6983620cffc6a1f2

                            
                                class Observer{
                                    constructor(){
                                        this.listeners = [];
                                    }
                                    addListener(name, callback){
                                        let id = {};
                                        this.listeners.push({id, name, callback});
                                        return id;
                                    }
                                    addOnceListener(name, callback){
                                        let id = {};
                                        this.listeners.push({id, name, callback:()=>{
                                            callback();
                                            this.removeListener(id);
                                            }
                                        });
                                        return id;
                                    }
                                    removeListener(id){
                                        this.listeners = this.listeners.filter(it=>it.id!=id);
                                    }
                                    dispatch(name){
                                        this.listeners.filter(it=>it.name==name).forEach(it=>it.callback());
                                    }
                                }
                            
                        

Did the Promise finish?

Not yet