MVCoconut / coconut.ui

Wow, such reactive view! Much awesome!
The Unlicense
89 stars 9 forks source link

Bug with Scheduler? "Uncaught (in promise) ReferenceError: process is not defined" #90

Closed grepsuzette closed 2 years ago

grepsuzette commented 2 years ago

Note sure if I did something wrong. Seems some problem with Scheduler

Haxe 4.2.3, Lib versions: most recent

import coconut.Ui;
import coconut.Ui.hxx;
import coconut.ui.*;
using tink.CoreApi;

class T {
    public static function main() {
        var doc = js.Browser.document;
        var div = doc.createDivElement();
        js.Browser.document.body.appendChild(div);
        var m = new M();
        Renderer.mount( div, hxx('<V m=${m}/>'));
    }

    public static function promf1() : Promise<String> {
        var tr = Future.trigger();
        Future.delay( 2000, () -> tr.trigger(Success("f1")));
        return tr.asFuture();
    }

    public static function promf2() : Promise<String> 
         return Promise.lift("f2");

}

class M implements coconut.data.Model {
    @:editable var revision : Int = @byDefault 0;
    @:loaded var s : String = { revision; 
       if (revision == 0) T.promf1();                 
       else T.promf2()
        ;
    }
    // my actual goal was to call touch, but 
    // I don't make the call for this bug report
    public function touch() { revision++; }
}

class V extends coconut.ui.View {
    @:attr var m : M;
    function render()
        <>
            <switch {m.s}>
                <case {Done(v)}>{v}
                <case {_}>....
            </switch>
        </>
    ;
}

The error:

Uncaught (in promise) ReferenceError: process is not defined
    progress Scheduler.hx:140
    tryFinally Error.hx:167
    progress Scheduler.hx:139
    batcher Scheduler.hx:42
    promise callback*asap1 Scheduler.hx:36
    batcher Scheduler.hx:42
    schedule Scheduler.hx:160
    invalidateParent Parent.hx:36
    scheduleUpdate Parent.hx:17
    invalidateParent Parent.hx:38
    invalidate WidgetLifeCycle.hx:49
    node Invalidatable.hx:65
    invoke Callback.hx:231
    fire Invalidatable.hx:77
    invalidate AutoObservable.hx:305
    node Invalidatable.hx:65
    invoke Callback.hx:231
    fire Invalidatable.hx:77
    update AutoObservable.hx:283
    link AutoObservable.hx:34
    invoke Callback.hx:231
    trigger Future.hx:471
    promf1 T.hx:32
    compute Lazy.hx:106
    get Lazy.hx:13
    this1 Future.hx:373
    run Timer.hx:144
    id Timer.hx:73
    setInterval handler*haxe_Timer Timer.hx:73
    delay Timer.hx:141
    this1 Future.hx:373
    irreversible Future.hx:320
    arm Future.hx:534
    eager Future.hx:540
    delay Future.hx:373
    promf1 T.hx:28
    ret T.hx:46
    this1 AutoObservable.hx:34
    doCompute AutoObservable.hx:228
    getValue AutoObservable.hx:274
    get_value Observable.hx:37
    render T.hx:58
    V ViewBuilder.hx:731
    renderView ViewBuilder.hx:934
    this1 AutoObservable.hx:65
    doCompute AutoObservable.hx:228
    getValue AutoObservable.hx:274
    get_value Observable.hx:37
    poll WidgetLifeCycle.hx:30
    coconut_diffing_internal_WidgetLifeCycle WidgetLifeCycle.hx:24
    coconut_diffing_internal_RWidget VWidget.hx:34
    render VWidget.hx:20
    update RCell.hx:41
    render Root.hx:28
    withLater Parent.hx:22
    render Root.hx:28
    mountInto Renderer.hx:11
    main Renderer.macro.hx:8
    <anonymous> t.js:2772
    <anonymous> t.js:2773

Below is Scheduler.hx:140 as reported browser source map:

  public function progress(maxSeconds:Float)
    return @:privateAccess Observable.performUpdate(() -> {
      var end = measure() + maxSeconds;     // <- line 140

      do {
        var old = queue;

Any idea?

kevinresol commented 2 years ago

did you accidentially add the nodejs flag somehow (maybe via -lib hxnodejs)? https://github.com/HaxeFoundation/haxe/blob/bf9ff69c0801082174f0b2b0a66faeb5356de580/std/haxe/Timer.hx#L178

grepsuzette commented 2 years ago

Ooooops, that was exactly it ^^ Thank you

(note for future visitors: process is available for node, not from a browser)